1
0
mirror of https://git.libssh.org/projects/libssh.git synced 2025-07-29 13:01:13 +03:00

updated the sftp subsystem to follow the type conv

This commit is contained in:
Aris Adamantiadis
2009-10-10 20:55:17 +02:00
parent 499f9aa707
commit e74305c5eb
4 changed files with 323 additions and 316 deletions

View File

@ -37,7 +37,7 @@ clients must be made or how a client should react.
#define MAXCMD 10 #define MAXCMD 10
char *host; char *host;
char *user; char *user;
int sftp; int is_sftp;
char *cmds[MAXCMD]; char *cmds[MAXCMD];
struct termios terminal; struct termios terminal;
@ -97,7 +97,7 @@ static void usage(){
static int opts(int argc, char **argv){ static int opts(int argc, char **argv){
int i; int i;
if(strstr(argv[0],"sftp")) if(strstr(argv[0],"sftp"))
sftp=1; is_sftp=1;
// for(i=0;i<argc;i++) // for(i=0;i<argc;i++)
// printf("%d : %s\n",i,argv[i]); // printf("%d : %s\n",i,argv[i]);
/* insert your own arguments here */ /* insert your own arguments here */
@ -311,13 +311,13 @@ static void batch_shell(ssh_session session){
#ifdef WITH_SFTP #ifdef WITH_SFTP
/* it's just a proof of concept code for sftp, till i write a real documentation about it */ /* it's just a proof of concept code for sftp, till i write a real documentation about it */
void do_sftp(ssh_session session){ void do_sftp(ssh_session session){
SFTP_SESSION *sftp_session=sftp_new(session); sftp_session sftp=sftp_new(session);
SFTP_DIR *dir; sftp_dir dir;
SFTP_ATTRIBUTES *file; sftp_attributes file;
SFTP_STATVFS *sftpstatvfs; sftp_statvfs_t sftpstatvfs;
struct statvfs sysstatvfs; struct statvfs sysstatvfs;
SFTP_FILE *fichier; sftp_file fichier;
SFTP_FILE *to; sftp_file to;
int len=1; int len=1;
unsigned int i; unsigned int i;
char data[8000]={0}; char data[8000]={0};
@ -325,43 +325,43 @@ void do_sftp(ssh_session session){
unsigned int count; unsigned int count;
if(!sftp_session){ if(!sftp){
fprintf(stderr, "sftp error initialising channel: %s\n", fprintf(stderr, "sftp error initialising channel: %s\n",
ssh_get_error(session)); ssh_get_error(session));
return; return;
} }
if(sftp_init(sftp_session)){ if(sftp_init(sftp)){
fprintf(stderr, "error initialising sftp: %s\n", fprintf(stderr, "error initialising sftp: %s\n",
ssh_get_error(session)); ssh_get_error(session));
return; return;
} }
printf("Additional SFTP extensions provided by the server:\n"); printf("Additional SFTP extensions provided by the server:\n");
count = sftp_extensions_get_count(sftp_session); count = sftp_extensions_get_count(sftp);
for (i = 0; i < count; i++) { for (i = 0; i < count; i++) {
printf("\t%s, version: %s\n", printf("\t%s, version: %s\n",
sftp_extensions_get_name(sftp_session, i), sftp_extensions_get_name(sftp, i),
sftp_extensions_get_data(sftp_session, i)); sftp_extensions_get_data(sftp, i));
} }
/* test symlink and readlink */ /* test symlink and readlink */
if (sftp_symlink(sftp_session, "/tmp/this_is_the_link", if (sftp_symlink(sftp, "/tmp/this_is_the_link",
"/tmp/sftp_symlink_test") < 0) { "/tmp/sftp_symlink_test") < 0) {
fprintf(stderr, "Could not create link (%s)\n", ssh_get_error(session)); fprintf(stderr, "Could not create link (%s)\n", ssh_get_error(session));
return; return;
} }
lnk = sftp_readlink(sftp_session, "/tmp/sftp_symlink_test"); lnk = sftp_readlink(sftp, "/tmp/sftp_symlink_test");
if (lnk == NULL) { if (lnk == NULL) {
fprintf(stderr, "Could not read link (%s)\n", ssh_get_error(session)); fprintf(stderr, "Could not read link (%s)\n", ssh_get_error(session));
return; return;
} }
printf("readlink /tmp/sftp_symlink_test: %s\n", lnk); printf("readlink /tmp/sftp_symlink_test: %s\n", lnk);
sftp_unlink(sftp_session, "/tmp/sftp_symlink_test"); sftp_unlink(sftp, "/tmp/sftp_symlink_test");
if (sftp_extension_supported(sftp_session, "statvfs@openssh.com", "2")) { if (sftp_extension_supported(sftp, "statvfs@openssh.com", "2")) {
sftpstatvfs = sftp_statvfs(sftp_session, "/tmp"); sftpstatvfs = sftp_statvfs(sftp, "/tmp");
if (sftpstatvfs == NULL) { if (sftpstatvfs == NULL) {
fprintf(stderr, "statvfs failed (%s)\n", ssh_get_error(session)); fprintf(stderr, "statvfs failed (%s)\n", ssh_get_error(session));
return; return;
@ -425,13 +425,13 @@ void do_sftp(ssh_session session){
/* the connection is made */ /* the connection is made */
/* opening a directory */ /* opening a directory */
dir=sftp_opendir(sftp_session,"./"); dir=sftp_opendir(sftp,"./");
if(!dir) { if(!dir) {
fprintf(stderr, "Directory not opened(%s)\n", ssh_get_error(session)); fprintf(stderr, "Directory not opened(%s)\n", ssh_get_error(session));
return ; return ;
} }
/* reading the whole directory, file by file */ /* reading the whole directory, file by file */
while((file=sftp_readdir(sftp_session,dir))){ while((file=sftp_readdir(sftp,dir))){
fprintf(stderr, "%30s(%.8o) : %.5d.%.5d : %.10llu bytes\n", fprintf(stderr, "%30s(%.8o) : %.5d.%.5d : %.10llu bytes\n",
file->name, file->name,
file->permissions, file->permissions,
@ -452,14 +452,14 @@ void do_sftp(ssh_session session){
/* this will open a file and copy it into your /home directory */ /* this will open a file and copy it into your /home directory */
/* the small buffer size was intended to stress the library. of course, you can use a buffer till 20kbytes without problem */ /* the small buffer size was intended to stress the library. of course, you can use a buffer till 20kbytes without problem */
fichier=sftp_open(sftp_session,"/usr/bin/ssh",O_RDONLY, 0); fichier=sftp_open(sftp,"/usr/bin/ssh",O_RDONLY, 0);
if(!fichier){ if(!fichier){
fprintf(stderr, "Error opening /usr/bin/ssh: %s\n", fprintf(stderr, "Error opening /usr/bin/ssh: %s\n",
ssh_get_error(session)); ssh_get_error(session));
return; return;
} }
/* open a file for writing... */ /* open a file for writing... */
to=sftp_open(sftp_session,"ssh-copy",O_WRONLY | O_CREAT, 0700); to=sftp_open(sftp,"ssh-copy",O_WRONLY | O_CREAT, 0700);
if(!to){ if(!to){
fprintf(stderr, "Error opening ssh-copy for writing: %s\n", fprintf(stderr, "Error opening ssh-copy for writing: %s\n",
ssh_get_error(session)); ssh_get_error(session));
@ -478,7 +478,7 @@ void do_sftp(ssh_session session){
sftp_close(fichier); sftp_close(fichier);
sftp_close(to); sftp_close(to);
printf("fichiers ferm\n"); printf("fichiers ferm\n");
to=sftp_open(sftp_session,"/tmp/grosfichier",O_WRONLY|O_CREAT, 0644); to=sftp_open(sftp,"/tmp/grosfichier",O_WRONLY|O_CREAT, 0644);
for(i=0;i<1000;++i){ for(i=0;i<1000;++i){
len=sftp_write(to,data,8000); len=sftp_write(to,data,8000);
printf("wrote %d bytes\n",len); printf("wrote %d bytes\n",len);
@ -489,7 +489,7 @@ void do_sftp(ssh_session session){
sftp_close(to); sftp_close(to);
/* close the sftp session */ /* close the sftp session */
sftp_free(sftp_session); sftp_free(sftp);
printf("sftp session terminated\n"); printf("sftp session terminated\n");
} }
#endif #endif
@ -682,10 +682,10 @@ int main(int argc, char **argv){
} }
ssh_log(session, SSH_LOG_FUNCTIONS, "Authentication success"); ssh_log(session, SSH_LOG_FUNCTIONS, "Authentication success");
if(strstr(argv[0],"sftp")){ if(strstr(argv[0],"sftp")){
sftp=1; is_sftp=1;
ssh_log(session, SSH_LOG_FUNCTIONS, "Doing sftp instead"); ssh_log(session, SSH_LOG_FUNCTIONS, "Doing sftp instead");
} }
if(!sftp){ if(!is_sftp){
if(!cmds[0]) if(!cmds[0])
shell(session); shell(session);
else else
@ -695,7 +695,7 @@ int main(int argc, char **argv){
else else
do_sftp(session); do_sftp(session);
#endif #endif
if(!sftp && !cmds[0]) if(!is_sftp && !cmds[0])
do_cleanup(0); do_cleanup(0);
ssh_disconnect(session); ssh_disconnect(session);
ssh_free(session); ssh_free(session);

View File

@ -25,12 +25,12 @@
* @brief SFTP handling functions * @brief SFTP handling functions
* *
* SFTP commands are channeled by the ssh sftp subsystem. Every packet is * SFTP commands are channeled by the ssh sftp subsystem. Every packet is
* sent/read using a SFTP_PACKET type structure. Related to these packets, * sent/read using a sftp_packet type structure. Related to these packets,
* most of the server answers are messages having an ID and a message * most of the server answers are messages having an ID and a message
* specific part. It is described by SFTP_MESSAGE when reading a message, * specific part. It is described by sftp_message when reading a message,
* the sftp system puts it into the queue, so the process having asked for * the sftp system puts it into the queue, so the process having asked for
* it can fetch it, while continuing to read for other messages (it is * it can fetch it, while continuing to read for other messages (it is
* inspecified in which order messages may be sent back to the client * unspecified in which order messages may be sent back to the client
* *
* @defgroup ssh_sftp SFTP Functions * @defgroup ssh_sftp SFTP Functions
* @{ * @{
@ -67,86 +67,96 @@ extern "C" {
#endif /* _MSC_VER */ #endif /* _MSC_VER */
#endif /* _WIN32 */ #endif /* _WIN32 */
typedef struct sftp_attributes_struct* sftp_attributes;
typedef struct sftp_client_message_struct* sftp_client_message;
typedef struct sftp_dir_struct* sftp_dir;
typedef struct sftp_ext_struct *sftp_ext; typedef struct sftp_ext_struct *sftp_ext;
typedef struct sftp_file_struct* sftp_file;
typedef struct sftp_message_struct* sftp_message;
typedef struct sftp_packet_struct* sftp_packet;
typedef struct sftp_request_queue_struct* sftp_request_queue;
typedef struct sftp_session_struct* sftp_session;
typedef struct sftp_status_message_struct* sftp_status_message;
typedef struct sftp_statvfs_struct* sftp_statvfs_t;
typedef struct sftp_session_struct { struct sftp_session_struct {
ssh_session session; ssh_session session;
ssh_channel channel; ssh_channel channel;
int server_version; int server_version;
int client_version; int client_version;
int version; int version;
struct request_queue *queue; sftp_request_queue queue;
uint32_t id_counter; uint32_t id_counter;
int errnum; int errnum;
void **handles; void **handles;
struct sftp_ext_struct *ext; sftp_ext ext;
} SFTP_SESSION ; };
typedef struct { struct sftp_packet_struct {
SFTP_SESSION *sftp; sftp_session sftp;
uint8_t type; uint8_t type;
ssh_buffer payload; ssh_buffer payload;
} SFTP_PACKET; };
/* file handler */ /* file handler */
typedef struct sftp_file{ struct sftp_file_struct {
SFTP_SESSION *sftp; sftp_session sftp;
char *name; char *name;
uint64_t offset; uint64_t offset;
ssh_string handle; ssh_string handle;
int eof; int eof;
int nonblocking; int nonblocking;
} SFTP_FILE ; };
typedef struct sftp_dir { struct sftp_dir_struct {
SFTP_SESSION *sftp; sftp_session sftp;
char *name; char *name;
ssh_string handle; /* handle to directory */ ssh_string handle; /* handle to directory */
ssh_buffer buffer; /* contains raw attributes from server which haven't been parsed */ ssh_buffer buffer; /* contains raw attributes from server which haven't been parsed */
uint32_t count; /* counts the number of following attributes structures into buffer */ uint32_t count; /* counts the number of following attributes structures into buffer */
int eof; /* end of directory listing */ int eof; /* end of directory listing */
} SFTP_DIR; };
typedef struct { struct sftp_message_struct {
SFTP_SESSION *sftp; sftp_session sftp;
uint8_t packet_type; uint8_t packet_type;
ssh_buffer payload; ssh_buffer payload;
uint32_t id; uint32_t id;
} SFTP_MESSAGE; };
/* this is a bunch of all data that could be into a message */ /* this is a bunch of all data that could be into a message */
typedef struct sftp_client_message{ struct sftp_client_message_struct {
SFTP_SESSION *sftp; sftp_session sftp;
uint8_t type; uint8_t type;
uint32_t id; uint32_t id;
char *filename; /* can be "path" */ char *filename; /* can be "path" */
uint32_t flags; uint32_t flags;
struct sftp_attributes *attr; sftp_attributes attr;
ssh_string handle; ssh_string handle;
uint64_t offset; uint64_t offset;
uint32_t len; uint32_t len;
int attr_num; int attr_num;
ssh_buffer attrbuf; /* used by sftp_reply_attrs */ ssh_buffer attrbuf; /* used by sftp_reply_attrs */
ssh_string data; /* can be newpath of rename() */ ssh_string data; /* can be newpath of rename() */
} SFTP_CLIENT_MESSAGE; };
typedef struct request_queue{ struct sftp_request_queue_struct {
struct request_queue *next; sftp_request_queue next;
SFTP_MESSAGE *message; sftp_message message;
} REQUEST_QUEUE; };
/* SSH_FXP_MESSAGE described into .7 page 26 */ /* SSH_FXP_MESSAGE described into .7 page 26 */
typedef struct { struct sftp_status_message_struct {
uint32_t id; uint32_t id;
uint32_t status; uint32_t status;
ssh_string error; ssh_string error;
ssh_string lang; ssh_string lang;
char *errormsg; char *errormsg;
char *langmsg; char *langmsg;
} STATUS_MESSAGE; };
/* don't worry much of these aren't really used */ /* don't worry much of these aren't really used */
typedef struct sftp_attributes{ struct sftp_attributes_struct {
char *name; char *name;
char *longname; /* some weird stuff */ char *longname; /* some weird stuff */
uint32_t flags; uint32_t flags;
@ -169,9 +179,9 @@ typedef struct sftp_attributes{
uint32_t extended_count; uint32_t extended_count;
ssh_string extended_type; ssh_string extended_type;
ssh_string extended_data; ssh_string extended_data;
} SFTP_ATTRIBUTES; };
typedef struct sftp_statvfs_struct { struct sftp_statvfs_struct {
uint64_t f_bsize; /* file system block size */ uint64_t f_bsize; /* file system block size */
uint64_t f_frsize; /* fundamental fs block size */ uint64_t f_frsize; /* fundamental fs block size */
uint64_t f_blocks; /* number of blocks (unit f_frsize) */ uint64_t f_blocks; /* number of blocks (unit f_frsize) */
@ -183,7 +193,7 @@ typedef struct sftp_statvfs_struct {
uint64_t f_fsid; /* file system id */ uint64_t f_fsid; /* file system id */
uint64_t f_flag; /* bit mask of f_flag values */ uint64_t f_flag; /* bit mask of f_flag values */
uint64_t f_namemax; /* maximum filename length */ uint64_t f_namemax; /* maximum filename length */
} SFTP_STATVFS; };
#define LIBSFTP_VERSION 3 #define LIBSFTP_VERSION 3
@ -194,14 +204,14 @@ typedef struct sftp_statvfs_struct {
* *
* @return A new sftp session or NULL on error. * @return A new sftp session or NULL on error.
*/ */
LIBSSH_API SFTP_SESSION *sftp_new(ssh_session session); LIBSSH_API sftp_session sftp_new(ssh_session session);
/** /**
* @brief Close and deallocate a sftp session. * @brief Close and deallocate a sftp session.
* *
* @param sftp The sftp session handle to free. * @param sftp The sftp session handle to free.
*/ */
LIBSSH_API void sftp_free(SFTP_SESSION *sftp); LIBSSH_API void sftp_free(sftp_session sftp);
/** /**
* @brief Initialize the sftp session with the server. * @brief Initialize the sftp session with the server.
@ -210,7 +220,7 @@ LIBSSH_API void sftp_free(SFTP_SESSION *sftp);
* *
* @return 0 on success, < 0 on error with ssh error set. * @return 0 on success, < 0 on error with ssh error set.
*/ */
LIBSSH_API int sftp_init(SFTP_SESSION *sftp); LIBSSH_API int sftp_init(sftp_session sftp);
/** /**
* @brief Get the last sftp error. * @brief Get the last sftp error.
@ -222,7 +232,7 @@ LIBSSH_API int sftp_init(SFTP_SESSION *sftp);
* @return The saved error (see server responses), < 0 if an error * @return The saved error (see server responses), < 0 if an error
* in the function occured. * in the function occured.
*/ */
LIBSSH_API int sftp_get_error(SFTP_SESSION *sftp); LIBSSH_API int sftp_get_error(sftp_session sftp);
/** /**
* @brief Get the count of extensions provided by the server. * @brief Get the count of extensions provided by the server.
@ -232,7 +242,7 @@ LIBSSH_API int sftp_get_error(SFTP_SESSION *sftp);
* @return The count of extensions provided by the server, 0 on error or * @return The count of extensions provided by the server, 0 on error or
* not available. * not available.
*/ */
LIBSSH_API unsigned int sftp_extensions_get_count(SFTP_SESSION *sftp); LIBSSH_API unsigned int sftp_extensions_get_count(sftp_session sftp);
/** /**
* @brief Get the name of the extension provided by the server. * @brief Get the name of the extension provided by the server.
@ -243,7 +253,7 @@ LIBSSH_API unsigned int sftp_extensions_get_count(SFTP_SESSION *sftp);
* *
* @return The name of the extension. * @return The name of the extension.
*/ */
LIBSSH_API const char *sftp_extensions_get_name(SFTP_SESSION *sftp, unsigned int index); LIBSSH_API const char *sftp_extensions_get_name(sftp_session sftp, unsigned int index);
/** /**
* @brief Get the data of the extension provided by the server. * @brief Get the data of the extension provided by the server.
@ -256,7 +266,7 @@ LIBSSH_API const char *sftp_extensions_get_name(SFTP_SESSION *sftp, unsigned int
* *
* @return The data of the extension. * @return The data of the extension.
*/ */
LIBSSH_API const char *sftp_extensions_get_data(SFTP_SESSION *sftp, unsigned int index); LIBSSH_API const char *sftp_extensions_get_data(sftp_session sftp, unsigned int index);
/** /**
* @brief Check if the given extension is supported. * @brief Check if the given extension is supported.
@ -275,7 +285,7 @@ LIBSSH_API const char *sftp_extensions_get_data(SFTP_SESSION *sftp, unsigned int
* sftp_extension_supported(sftp, "statvfs@openssh.com", "2"); * sftp_extension_supported(sftp, "statvfs@openssh.com", "2");
* @endcode * @endcode
*/ */
LIBSSH_API int sftp_extension_supported(SFTP_SESSION *sftp, const char *name, LIBSSH_API int sftp_extension_supported(sftp_session sftp, const char *name,
const char *data); const char *data);
/** /**
@ -290,7 +300,7 @@ LIBSSH_API int sftp_extension_supported(SFTP_SESSION *sftp, const char *name,
* @see sftp_readdir * @see sftp_readdir
* @see sftp_closedir * @see sftp_closedir
*/ */
LIBSSH_API SFTP_DIR *sftp_opendir(SFTP_SESSION *session, const char *path); LIBSSH_API sftp_dir sftp_opendir(sftp_session session, const char *path);
/** /**
* @brief Get a single file attributes structure of a directory. * @brief Get a single file attributes structure of a directory.
@ -305,7 +315,7 @@ LIBSSH_API SFTP_DIR *sftp_opendir(SFTP_SESSION *session, const char *path);
* @see sftp_attribute_free() * @see sftp_attribute_free()
* @see sftp_closedir() * @see sftp_closedir()
*/ */
LIBSSH_API SFTP_ATTRIBUTES *sftp_readdir(SFTP_SESSION *session, SFTP_DIR *dir); LIBSSH_API sftp_attributes sftp_readdir(sftp_session session, sftp_dir dir);
/** /**
* @brief Tell if the directory has reached EOF (End Of File). * @brief Tell if the directory has reached EOF (End Of File).
@ -316,7 +326,7 @@ LIBSSH_API SFTP_ATTRIBUTES *sftp_readdir(SFTP_SESSION *session, SFTP_DIR *dir);
* *
* @see sftp_readdir() * @see sftp_readdir()
*/ */
LIBSSH_API int sftp_dir_eof(SFTP_DIR *dir); LIBSSH_API int sftp_dir_eof(sftp_dir dir);
/** /**
* @brief Get information about a file or directory. * @brief Get information about a file or directory.
@ -328,7 +338,7 @@ LIBSSH_API int sftp_dir_eof(SFTP_DIR *dir);
* @return The sftp attributes structure of the file or directory, * @return The sftp attributes structure of the file or directory,
* NULL on error with ssh and sftp error set. * NULL on error with ssh and sftp error set.
*/ */
LIBSSH_API SFTP_ATTRIBUTES *sftp_stat(SFTP_SESSION *session, const char *path); LIBSSH_API sftp_attributes sftp_stat(sftp_session session, const char *path);
/** /**
* @brief Get information about a file or directory. * @brief Get information about a file or directory.
@ -343,7 +353,7 @@ LIBSSH_API SFTP_ATTRIBUTES *sftp_stat(SFTP_SESSION *session, const char *path);
* @return The sftp attributes structure of the file or directory, * @return The sftp attributes structure of the file or directory,
* NULL on error with ssh and sftp error set. * NULL on error with ssh and sftp error set.
*/ */
LIBSSH_API SFTP_ATTRIBUTES *sftp_lstat(SFTP_SESSION *session, const char *path); LIBSSH_API sftp_attributes sftp_lstat(sftp_session session, const char *path);
/** /**
* @brief Get information about a file or directory from a file handle. * @brief Get information about a file or directory from a file handle.
@ -353,14 +363,14 @@ LIBSSH_API SFTP_ATTRIBUTES *sftp_lstat(SFTP_SESSION *session, const char *path);
* @return The sftp attributes structure of the file or directory, * @return The sftp attributes structure of the file or directory,
* NULL on error with ssh and sftp error set. * NULL on error with ssh and sftp error set.
*/ */
LIBSSH_API SFTP_ATTRIBUTES *sftp_fstat(SFTP_FILE *file); LIBSSH_API sftp_attributes sftp_fstat(sftp_file file);
/** /**
* @brief Free a sftp attribute structure. * @brief Free a sftp attribute structure.
* *
* @param file The sftp attribute structure to free. * @param file The sftp attribute structure to free.
*/ */
LIBSSH_API void sftp_attributes_free(SFTP_ATTRIBUTES *file); LIBSSH_API void sftp_attributes_free(sftp_attributes file);
/** /**
* @brief Close a directory handle opened by sftp_opendir(). * @brief Close a directory handle opened by sftp_opendir().
@ -369,12 +379,12 @@ LIBSSH_API void sftp_attributes_free(SFTP_ATTRIBUTES *file);
* *
* @return Returns SSH_NO_ERROR or SSH_ERROR if an error occured. * @return Returns SSH_NO_ERROR or SSH_ERROR if an error occured.
*/ */
LIBSSH_API int sftp_closedir(SFTP_DIR *dir); LIBSSH_API int sftp_closedir(sftp_dir dir);
/** /**
* @deprecated Use sftp_closedir() instead. * @deprecated Use sftp_closedir() instead.
*/ */
LIBSSH_API int sftp_dir_close(SFTP_DIR *dir) SFTP_DEPRECATED; LIBSSH_API int sftp_dir_close(sftp_dir dir) SFTP_DEPRECATED;
/** /**
* @brief Close an open file handle. * @brief Close an open file handle.
@ -385,12 +395,12 @@ LIBSSH_API int sftp_dir_close(SFTP_DIR *dir) SFTP_DEPRECATED;
* *
* @see sftp_open() * @see sftp_open()
*/ */
LIBSSH_API int sftp_close(SFTP_FILE *file); LIBSSH_API int sftp_close(sftp_file file);
/** /**
* @deprecated Use sftp_close() instead. * @deprecated Use sftp_close() instead.
*/ */
LIBSSH_API int sftp_file_close(SFTP_FILE *file) SFTP_DEPRECATED; LIBSSH_API int sftp_file_close(sftp_file file) SFTP_DEPRECATED;
/** /**
* @brief Open a file on the server. * @brief Open a file on the server.
@ -418,12 +428,12 @@ LIBSSH_API int sftp_file_close(SFTP_FILE *file) SFTP_DEPRECATED;
* @return A sftp file handle, NULL on error with ssh and sftp * @return A sftp file handle, NULL on error with ssh and sftp
* error set. * error set.
*/ */
LIBSSH_API SFTP_FILE *sftp_open(SFTP_SESSION *session, const char *file, int accesstype, LIBSSH_API sftp_file sftp_open(sftp_session session, const char *file, int accesstype,
mode_t mode); mode_t mode);
LIBSSH_API void sftp_file_set_nonblocking(SFTP_FILE *handle); LIBSSH_API void sftp_file_set_nonblocking(sftp_file handle);
LIBSSH_API void sftp_file_set_blocking(SFTP_FILE *handle); LIBSSH_API void sftp_file_set_blocking(sftp_file handle);
/** /**
* @brief Read from a file using an opened sftp file handle. * @brief Read from a file using an opened sftp file handle.
@ -437,7 +447,7 @@ LIBSSH_API void sftp_file_set_blocking(SFTP_FILE *handle);
* @return Number of bytes written, < 0 on error with ssh and sftp * @return Number of bytes written, < 0 on error with ssh and sftp
* error set. * error set.
*/ */
LIBSSH_API ssize_t sftp_read(SFTP_FILE *file, void *buf, size_t count); LIBSSH_API ssize_t sftp_read(sftp_file file, void *buf, size_t count);
/** /**
* @brief Start an asynchronous read from a file using an opened sftp file handle. * @brief Start an asynchronous read from a file using an opened sftp file handle.
@ -470,7 +480,7 @@ LIBSSH_API ssize_t sftp_read(SFTP_FILE *file, void *buf, size_t count);
* @see sftp_async_read() * @see sftp_async_read()
* @see sftp_open() * @see sftp_open()
*/ */
LIBSSH_API int sftp_async_read_begin(SFTP_FILE *file, uint32_t len); LIBSSH_API int sftp_async_read_begin(sftp_file file, uint32_t len);
/** /**
* @brief Wait for an asynchronous read to complete and save the data. * @brief Wait for an asynchronous read to complete and save the data.
@ -495,7 +505,7 @@ LIBSSH_API int sftp_async_read_begin(SFTP_FILE *file, uint32_t len);
* *
* @see sftp_async_read_begin() * @see sftp_async_read_begin()
*/ */
LIBSSH_API int sftp_async_read(SFTP_FILE *file, void *data, uint32_t len, uint32_t id); LIBSSH_API int sftp_async_read(sftp_file file, void *data, uint32_t len, uint32_t id);
/** /**
* @brief Write to a file using an opened sftp file handle. * @brief Write to a file using an opened sftp file handle.
@ -513,7 +523,7 @@ LIBSSH_API int sftp_async_read(SFTP_FILE *file, void *data, uint32_t len, uint32
* @see sftp_read() * @see sftp_read()
* @see sftp_close() * @see sftp_close()
*/ */
LIBSSH_API ssize_t sftp_write(SFTP_FILE *file, const void *buf, size_t count); LIBSSH_API ssize_t sftp_write(sftp_file file, const void *buf, size_t count);
/** /**
* @brief Seek to a specific location in a file. * @brief Seek to a specific location in a file.
@ -524,7 +534,7 @@ LIBSSH_API ssize_t sftp_write(SFTP_FILE *file, const void *buf, size_t count);
* *
* @return 0 on success, < 0 on error. * @return 0 on success, < 0 on error.
*/ */
LIBSSH_API int sftp_seek(SFTP_FILE *file, uint32_t new_offset); LIBSSH_API int sftp_seek(sftp_file file, uint32_t new_offset);
/** /**
* @brief Seek to a specific location in a file. This is the * @brief Seek to a specific location in a file. This is the
@ -536,7 +546,7 @@ LIBSSH_API int sftp_seek(SFTP_FILE *file, uint32_t new_offset);
* *
* @return 0 on success, < 0 on error. * @return 0 on success, < 0 on error.
*/ */
LIBSSH_API int sftp_seek64(SFTP_FILE *file, uint64_t new_offset); LIBSSH_API int sftp_seek64(sftp_file file, uint64_t new_offset);
/** /**
* @brief Report current byte position in file. * @brief Report current byte position in file.
@ -547,7 +557,7 @@ LIBSSH_API int sftp_seek64(SFTP_FILE *file, uint64_t new_offset);
* of the file associated with the file descriptor. < 0 on * of the file associated with the file descriptor. < 0 on
* error. * error.
*/ */
LIBSSH_API unsigned long sftp_tell(SFTP_FILE *file); LIBSSH_API unsigned long sftp_tell(sftp_file file);
/** /**
* @brief Report current byte position in file. * @brief Report current byte position in file.
@ -558,7 +568,7 @@ LIBSSH_API unsigned long sftp_tell(SFTP_FILE *file);
* of the file associated with the file descriptor. < 0 on * of the file associated with the file descriptor. < 0 on
* error. * error.
*/ */
LIBSSH_API uint64_t sftp_tell64(SFTP_FILE *file); LIBSSH_API uint64_t sftp_tell64(sftp_file file);
/** /**
* @brief Rewinds the position of the file pointer to the beginning of the * @brief Rewinds the position of the file pointer to the beginning of the
@ -566,12 +576,12 @@ LIBSSH_API uint64_t sftp_tell64(SFTP_FILE *file);
* *
* @param file Open sftp file handle. * @param file Open sftp file handle.
*/ */
LIBSSH_API void sftp_rewind(SFTP_FILE *file); LIBSSH_API void sftp_rewind(sftp_file file);
/** /**
* @deprecated Use sftp_unlink() instead. * @deprecated Use sftp_unlink() instead.
*/ */
LIBSSH_API int sftp_rm(SFTP_SESSION *sftp, const char *file) SFTP_DEPRECATED; LIBSSH_API int sftp_rm(sftp_session sftp, const char *file) SFTP_DEPRECATED;
/** /**
* @brief Unlink (delete) a file. * @brief Unlink (delete) a file.
@ -582,7 +592,7 @@ LIBSSH_API int sftp_rm(SFTP_SESSION *sftp, const char *file) SFTP_DEPRECATED;
* *
* @return 0 on success, < 0 on error with ssh and sftp error set. * @return 0 on success, < 0 on error with ssh and sftp error set.
*/ */
LIBSSH_API int sftp_unlink(SFTP_SESSION *sftp, const char *file); LIBSSH_API int sftp_unlink(sftp_session sftp, const char *file);
/** /**
* @brief Remove a directoy. * @brief Remove a directoy.
@ -593,7 +603,7 @@ LIBSSH_API int sftp_unlink(SFTP_SESSION *sftp, const char *file);
* *
* @return 0 on success, < 0 on error with ssh and sftp error set. * @return 0 on success, < 0 on error with ssh and sftp error set.
*/ */
LIBSSH_API int sftp_rmdir(SFTP_SESSION *sftp, const char *directory); LIBSSH_API int sftp_rmdir(sftp_session sftp, const char *directory);
/** /**
* @brief Create a directory. * @brief Create a directory.
@ -608,7 +618,7 @@ LIBSSH_API int sftp_rmdir(SFTP_SESSION *sftp, const char *directory);
* *
* @return 0 on success, < 0 on error with ssh and sftp error set. * @return 0 on success, < 0 on error with ssh and sftp error set.
*/ */
LIBSSH_API int sftp_mkdir(SFTP_SESSION *sftp, const char *directory, mode_t mode); LIBSSH_API int sftp_mkdir(sftp_session sftp, const char *directory, mode_t mode);
/** /**
* @brief Rename or move a file or directory. * @brief Rename or move a file or directory.
@ -623,7 +633,7 @@ LIBSSH_API int sftp_mkdir(SFTP_SESSION *sftp, const char *directory, mode_t mode
* *
* @return 0 on success, < 0 on error with ssh and sftp error set. * @return 0 on success, < 0 on error with ssh and sftp error set.
*/ */
LIBSSH_API int sftp_rename(SFTP_SESSION *sftp, const char *original, const char *newname); LIBSSH_API int sftp_rename(sftp_session sftp, const char *original, const char *newname);
/** /**
* @brief Set file attributes on a file, directory or symbolic link. * @brief Set file attributes on a file, directory or symbolic link.
@ -637,7 +647,7 @@ LIBSSH_API int sftp_rename(SFTP_SESSION *sftp, const char *original, const char
* *
* @return 0 on success, < 0 on error with ssh and sftp error set. * @return 0 on success, < 0 on error with ssh and sftp error set.
*/ */
LIBSSH_API int sftp_setstat(SFTP_SESSION *sftp, const char *file, SFTP_ATTRIBUTES *attr); LIBSSH_API int sftp_setstat(sftp_session sftp, const char *file, sftp_attributes attr);
/** /**
* @brief Change the file owner and group * @brief Change the file owner and group
@ -652,7 +662,7 @@ LIBSSH_API int sftp_setstat(SFTP_SESSION *sftp, const char *file, SFTP_ATTRIBUTE
* *
* @return 0 on success, < 0 on error with ssh and sftp error set. * @return 0 on success, < 0 on error with ssh and sftp error set.
*/ */
LIBSSH_API int sftp_chown(SFTP_SESSION *sftp, const char *file, uid_t owner, gid_t group); LIBSSH_API int sftp_chown(sftp_session sftp, const char *file, uid_t owner, gid_t group);
/** /**
* @brief Change permissions of a file * @brief Change permissions of a file
@ -667,7 +677,7 @@ LIBSSH_API int sftp_chown(SFTP_SESSION *sftp, const char *file, uid_t owner, gid
* *
* @return 0 on success, < 0 on error with ssh and sftp error set. * @return 0 on success, < 0 on error with ssh and sftp error set.
*/ */
LIBSSH_API int sftp_chmod(SFTP_SESSION *sftp, const char *file, mode_t mode); LIBSSH_API int sftp_chmod(sftp_session sftp, const char *file, mode_t mode);
/** /**
* @brief Change the last modification and access time of a file. * @brief Change the last modification and access time of a file.
@ -681,7 +691,7 @@ LIBSSH_API int sftp_chmod(SFTP_SESSION *sftp, const char *file, mode_t mode);
* *
* @return 0 on success, < 0 on error with ssh and sftp error set. * @return 0 on success, < 0 on error with ssh and sftp error set.
*/ */
LIBSSH_API int sftp_utimes(SFTP_SESSION *sftp, const char *file, const struct timeval *times); LIBSSH_API int sftp_utimes(sftp_session sftp, const char *file, const struct timeval *times);
/** /**
* @brief Create a symbolic link. * @brief Create a symbolic link.
@ -694,7 +704,7 @@ LIBSSH_API int sftp_utimes(SFTP_SESSION *sftp, const char *file, const struct ti
* *
* @return 0 on success, < 0 on error with ssh and sftp error set. * @return 0 on success, < 0 on error with ssh and sftp error set.
*/ */
LIBSSH_API int sftp_symlink(SFTP_SESSION *sftp, const char *target, const char *dest); LIBSSH_API int sftp_symlink(sftp_session sftp, const char *target, const char *dest);
/** /**
* @brief Read the value of a symbolic link. * @brief Read the value of a symbolic link.
@ -705,7 +715,7 @@ LIBSSH_API int sftp_symlink(SFTP_SESSION *sftp, const char *target, const char *
* *
* @return The target of the link, NULL on error. * @return The target of the link, NULL on error.
*/ */
LIBSSH_API char *sftp_readlink(SFTP_SESSION *sftp, const char *path); LIBSSH_API char *sftp_readlink(sftp_session sftp, const char *path);
/** /**
* @brief Get information about a mounted file system. * @brief Get information about a mounted file system.
@ -716,7 +726,7 @@ LIBSSH_API char *sftp_readlink(SFTP_SESSION *sftp, const char *path);
* *
* @return A statvfs structure or NULL on error. * @return A statvfs structure or NULL on error.
*/ */
LIBSSH_API SFTP_STATVFS *sftp_statvfs(SFTP_SESSION *sftp, const char *path); LIBSSH_API sftp_statvfs_t sftp_statvfs(sftp_session sftp, const char *path);
/** /**
* @brief Get information about a mounted file system. * @brief Get information about a mounted file system.
@ -725,14 +735,14 @@ LIBSSH_API SFTP_STATVFS *sftp_statvfs(SFTP_SESSION *sftp, const char *path);
* *
* @return A statvfs structure or NULL on error. * @return A statvfs structure or NULL on error.
*/ */
LIBSSH_API SFTP_STATVFS *sftp_fstatvfs(SFTP_FILE *file); LIBSSH_API sftp_statvfs_t sftp_fstatvfs(sftp_file file);
/** /**
* @brief Free the memory of an allocated statvfs. * @brief Free the memory of an allocated statvfs.
* *
* @param statvfs_o The statvfs to free. * @param statvfs_o The statvfs to free.
*/ */
LIBSSH_API void sftp_statvfs_free(SFTP_STATVFS *statvfs_o); LIBSSH_API void sftp_statvfs_free(sftp_statvfs_t statvfs_o);
/** /**
* @brief Canonicalize a sftp path. * @brief Canonicalize a sftp path.
@ -743,7 +753,7 @@ LIBSSH_API void sftp_statvfs_free(SFTP_STATVFS *statvfs_o);
* *
* @return The canonicalize path, NULL on error. * @return The canonicalize path, NULL on error.
*/ */
LIBSSH_API char *sftp_canonicalize_path(SFTP_SESSION *sftp, const char *path); LIBSSH_API char *sftp_canonicalize_path(sftp_session sftp, const char *path);
/** /**
* @brief Get the version of the SFTP protocol supported by the server * @brief Get the version of the SFTP protocol supported by the server
@ -752,7 +762,7 @@ LIBSSH_API char *sftp_canonicalize_path(SFTP_SESSION *sftp, const char *path);
* *
* @return The server version. * @return The server version.
*/ */
LIBSSH_API int sftp_server_version(SFTP_SESSION *sftp); LIBSSH_API int sftp_server_version(sftp_session sftp);
#ifdef WITH_SERVER #ifdef WITH_SERVER
/** /**
@ -764,7 +774,7 @@ LIBSSH_API int sftp_server_version(SFTP_SESSION *sftp);
* *
* @return A new sftp server session. * @return A new sftp server session.
*/ */
LIBSSH_API SFTP_SESSION *sftp_server_new(ssh_session session, ssh_channel chan); LIBSSH_API sftp_session sftp_server_new(ssh_session session, ssh_channel chan);
/** /**
* @brief Intialize the sftp server. * @brief Intialize the sftp server.
@ -773,32 +783,32 @@ LIBSSH_API SFTP_SESSION *sftp_server_new(ssh_session session, ssh_channel chan);
* *
* @return 0 on success, < 0 on error. * @return 0 on success, < 0 on error.
*/ */
LIBSSH_API int sftp_server_init(SFTP_SESSION *sftp); LIBSSH_API int sftp_server_init(sftp_session sftp);
#endif /* WITH_SERVER */ #endif /* WITH_SERVER */
/* this is not a public interface */ /* this is not a public interface */
#define SFTP_HANDLES 256 #define SFTP_HANDLES 256
SFTP_PACKET *sftp_packet_read(SFTP_SESSION *sftp); sftp_packet sftp_packet_read(sftp_session 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);
void sftp_packet_free(SFTP_PACKET *packet); void sftp_packet_free(sftp_packet packet);
int buffer_add_attributes(ssh_buffer buffer, SFTP_ATTRIBUTES *attr); int buffer_add_attributes(ssh_buffer buffer, sftp_attributes attr);
SFTP_ATTRIBUTES *sftp_parse_attr(SFTP_SESSION *session, ssh_buffer buf,int expectname); sftp_attributes sftp_parse_attr(sftp_session session, ssh_buffer buf,int expectname);
/* sftpserver.c */ /* sftpserver.c */
SFTP_CLIENT_MESSAGE *sftp_get_client_message(SFTP_SESSION *sftp); sftp_client_message sftp_get_client_message(sftp_session sftp);
void sftp_client_message_free(SFTP_CLIENT_MESSAGE *msg); void sftp_client_message_free(sftp_client_message msg);
int sftp_reply_name(SFTP_CLIENT_MESSAGE *msg, const char *name, int sftp_reply_name(sftp_client_message msg, const char *name,
SFTP_ATTRIBUTES *attr); sftp_attributes attr);
int sftp_reply_handle(SFTP_CLIENT_MESSAGE *msg, ssh_string handle); int sftp_reply_handle(sftp_client_message msg, ssh_string handle);
ssh_string sftp_handle_alloc(SFTP_SESSION *sftp, void *info); ssh_string sftp_handle_alloc(sftp_session sftp, void *info);
int sftp_reply_attr(SFTP_CLIENT_MESSAGE *msg, SFTP_ATTRIBUTES *attr); int sftp_reply_attr(sftp_client_message msg, sftp_attributes attr);
void *sftp_handle(SFTP_SESSION *sftp, ssh_string handle); void *sftp_handle(sftp_session sftp, ssh_string handle);
int sftp_reply_status(SFTP_CLIENT_MESSAGE *msg, uint32_t status, const char *message); int sftp_reply_status(sftp_client_message msg, uint32_t status, const char *message);
int sftp_reply_names_add(SFTP_CLIENT_MESSAGE *msg, const char *file, int sftp_reply_names_add(sftp_client_message msg, const char *file,
const char *longname, SFTP_ATTRIBUTES *attr); const char *longname, sftp_attributes attr);
int sftp_reply_names(SFTP_CLIENT_MESSAGE *msg); int sftp_reply_names(sftp_client_message msg);
int sftp_reply_data(SFTP_CLIENT_MESSAGE *msg, const void *data, int len); int sftp_reply_data(sftp_client_message msg, const void *data, int len);
void sftp_handle_remove(SFTP_SESSION *sftp, void *handle); void sftp_handle_remove(sftp_session sftp, void *handle);
/* SFTP commands and constants */ /* SFTP commands and constants */
#define SSH_FXP_INIT 1 #define SSH_FXP_INIT 1

View File

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

View File

@ -36,13 +36,13 @@
#include "libssh/buffer.h" #include "libssh/buffer.h"
#include "libssh/misc.h" #include "libssh/misc.h"
SFTP_CLIENT_MESSAGE *sftp_get_client_message(SFTP_SESSION *sftp) { sftp_client_message sftp_get_client_message(sftp_session sftp) {
SFTP_PACKET *packet; sftp_packet packet;
SFTP_CLIENT_MESSAGE *msg; sftp_client_message msg;
ssh_buffer payload; ssh_buffer payload;
ssh_string tmp; ssh_string tmp;
msg = malloc(sizeof (SFTP_CLIENT_MESSAGE)); msg = malloc(sizeof (struct sftp_client_message_struct));
if (msg == NULL) { if (msg == NULL) {
return NULL; return NULL;
} }
@ -213,7 +213,7 @@ SFTP_CLIENT_MESSAGE *sftp_get_client_message(SFTP_SESSION *sftp) {
return msg; return msg;
} }
void sftp_client_message_free(SFTP_CLIENT_MESSAGE *msg) { void sftp_client_message_free(sftp_client_message msg) {
if (msg == NULL) { if (msg == NULL) {
return; return;
} }
@ -227,8 +227,8 @@ void sftp_client_message_free(SFTP_CLIENT_MESSAGE *msg) {
SAFE_FREE(msg); SAFE_FREE(msg);
} }
int sftp_reply_name(SFTP_CLIENT_MESSAGE *msg, const char *name, int sftp_reply_name(sftp_client_message msg, const char *name,
SFTP_ATTRIBUTES *attr) { sftp_attributes attr) {
ssh_buffer out; ssh_buffer out;
ssh_string file; ssh_string file;
@ -259,7 +259,7 @@ int sftp_reply_name(SFTP_CLIENT_MESSAGE *msg, const char *name,
return 0; return 0;
} }
int sftp_reply_handle(SFTP_CLIENT_MESSAGE *msg, ssh_string handle){ int sftp_reply_handle(sftp_client_message msg, ssh_string handle){
ssh_buffer out; ssh_buffer out;
out = buffer_new(); out = buffer_new();
@ -278,7 +278,7 @@ int sftp_reply_handle(SFTP_CLIENT_MESSAGE *msg, ssh_string handle){
return 0; return 0;
} }
int sftp_reply_attr(SFTP_CLIENT_MESSAGE *msg, SFTP_ATTRIBUTES *attr) { int sftp_reply_attr(sftp_client_message msg, sftp_attributes attr) {
ssh_buffer out; ssh_buffer out;
out = buffer_new(); out = buffer_new();
@ -297,8 +297,8 @@ int sftp_reply_attr(SFTP_CLIENT_MESSAGE *msg, SFTP_ATTRIBUTES *attr) {
return 0; return 0;
} }
int sftp_reply_names_add(SFTP_CLIENT_MESSAGE *msg, const char *file, int sftp_reply_names_add(sftp_client_message msg, const char *file,
const char *longname, SFTP_ATTRIBUTES *attr) { const char *longname, sftp_attributes attr) {
ssh_string name; ssh_string name;
name = string_from_char(file); name = string_from_char(file);
@ -335,7 +335,7 @@ int sftp_reply_names_add(SFTP_CLIENT_MESSAGE *msg, const char *file,
return 0; return 0;
} }
int sftp_reply_names(SFTP_CLIENT_MESSAGE *msg) { int sftp_reply_names(sftp_client_message msg) {
ssh_buffer out; ssh_buffer out;
out = buffer_new(); out = buffer_new();
@ -363,7 +363,7 @@ int sftp_reply_names(SFTP_CLIENT_MESSAGE *msg) {
return 0; return 0;
} }
int sftp_reply_status(SFTP_CLIENT_MESSAGE *msg, uint32_t status, int sftp_reply_status(sftp_client_message msg, uint32_t status,
const char *message) { const char *message) {
ssh_buffer out; ssh_buffer out;
ssh_string s; ssh_string s;
@ -395,7 +395,7 @@ int sftp_reply_status(SFTP_CLIENT_MESSAGE *msg, uint32_t status,
return 0; return 0;
} }
int sftp_reply_data(SFTP_CLIENT_MESSAGE *msg, const void *data, int len) { int sftp_reply_data(sftp_client_message msg, const void *data, int len) {
ssh_buffer out; ssh_buffer out;
out = buffer_new(); out = buffer_new();
@ -421,7 +421,7 @@ int sftp_reply_data(SFTP_CLIENT_MESSAGE *msg, const void *data, int len) {
* 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).
*/ */
ssh_string sftp_handle_alloc(SFTP_SESSION *sftp, void *info) { ssh_string sftp_handle_alloc(sftp_session sftp, void *info) {
ssh_string ret; ssh_string ret;
uint32_t val; uint32_t val;
int i; int i;
@ -456,7 +456,7 @@ ssh_string sftp_handle_alloc(SFTP_SESSION *sftp, void *info) {
return ret; return ret;
} }
void *sftp_handle(SFTP_SESSION *sftp, ssh_string handle){ void *sftp_handle(sftp_session sftp, ssh_string handle){
uint32_t val; uint32_t val;
if (sftp->handles == NULL) { if (sftp->handles == NULL) {
@ -476,7 +476,7 @@ void *sftp_handle(SFTP_SESSION *sftp, ssh_string handle){
return sftp->handles[val]; return sftp->handles[val];
} }
void sftp_handle_remove(SFTP_SESSION *sftp, void *handle) { void sftp_handle_remove(sftp_session sftp, void *handle) {
int i; int i;
for (i = 0; i < SFTP_HANDLES; i++) { for (i = 0; i < SFTP_HANDLES; i++) {