/* tag: Scott Parish Sun Feb  2 13:03:45 2002 (sftp-protocol.h)
 */
/* sftp-protocol.h -
 *
 ****************************************************************
 * Copyright (C) 2002 Scott Parish
 * 
 * See the file "COPYING" for further information about
 * the copyright and warranty status of this work.
 */

#ifndef INCLUDE__SFTP_PROTOCOL__PROTOCOL_H
#define INCLUDE__SFTP_PROTOCOL__PROTOCOL_H

#include "hackerlab/machine/types.h"
#include "hackerlab/os/stdarg.h"
#include "hackerlab/mem/alloc-limits.h"



/* TODO: look through ssh/tcp/ethernet specks to find an optimal size */
#define SFTP_RWSIZE 16384
#define SFTP_DEFAULT_DIR_MODE 0755
#define SFTP_DEFAULT_FILE_MODE 0664

struct sftp_attrs 
{
  unsigned int flags;
  unsigned long long int size;
  unsigned int uid;
  unsigned int gid;
  unsigned int perms;
  unsigned int atime;
  unsigned int mtime;
  unsigned char *extended;
};



/* automatically generated __STDC__ prototypes */
extern char * sftp_abs_path (alloc_limits limits,
                             char *path);
extern int sftp_io_retry (t_uchar **text,
                          int (*func) (),
                          int fd,
                          char *buf,
                          unsigned int count);
extern int sftp_export_attrs (alloc_limits limits,
                              struct sftp_attrs *a,
                              char **pkt,
                              int *len);
extern int sftp_import_attrs (alloc_limits limits,
                              t_uchar ** text,
                              struct sftp_attrs *a,
                              char *pkt,
                              unsigned int pkt_len);
extern int sftp_decode_status (alloc_limits limits,
                               t_uchar **text,
                               char *pkt,
                               int pkt_len,
                               int i);
extern unsigned int sftp_server_response (alloc_limits limits,
                                          int *errn,
                                          t_uchar **text,
                                          int fd,
                                          char **pkt,
                                          int *pkt_len,
                                          int expected_response);
extern int sftp_write_pkt (alloc_limits limits,
                           int *errn,
                           t_uchar **text,
                           int fd,
                           char *fmt,
                           ...);
extern int sftp_is_dir (alloc_limits limits,
                        int * errn,
                        t_uchar ** text,
                        int in_fd,
                        int out_fd,
                        char * path);
extern int sftp_client_do_init (alloc_limits limits, int * errn, int * code,
                                t_uchar ** text, int in_fd, int out_fd);
extern int sftp_client_connect_and_login (int * in_fd,
                                          int * out_fd,
                                          alloc_limits limits,
                                          int * errn,
                                          int * code,
                                          t_uchar ** text,
                                          long * text_len,
                                          t_uchar * host);
extern int sftp_client_cwd (alloc_limits limits,
                            int * errn,
                            int * code,
                            t_uchar ** text,
                            long * text_len,
                            int in_fd,
                            int out_fd,
                            t_uchar * path);
extern int sftp_client_cdup (alloc_limits limits,
                             int * errn,
                             int * code,
                             t_uchar ** text,
                             int in_fd,
                             int out_fd);
extern int sftp_client_rename (alloc_limits limits,
                               int * errn,
                               int * code,
                               t_uchar ** text,
                               int in_fd,
                               int out_fd,
                               t_uchar * from,
                               t_uchar * to);
extern int sftp_client_unlink (alloc_limits limits,
                               int * errn,
                               int * code,
                               t_uchar ** text,
                               int in_fd,
                               int out_fd,
                               t_uchar * path);
extern int sftp_client_rmd (alloc_limits limits,
                            int * errn,
                            int * code,
                            t_uchar ** text,
                            int in_fd,
                            int out_fd,
                            t_uchar * path);
extern int sftp_client_mkd (alloc_limits limits,
                            int * errn,
                            int * code,
                            t_uchar ** text,
                            int in_fd,
                            int out_fd,
                            t_uchar * path);
extern int sftp_client_pwd (alloc_limits limits,
                            int * errn,
                            int * code,
                            t_uchar ** text,
                            int in_fd,
                            int out_fd);
extern int sftp_client_list (alloc_limits limits,
                             int *errn, int *code,
                             t_uchar ** text,
                             int in_fd,
                             int out_fd,
                             int data_fd,
                             t_uchar * path,
                             int longfmt);
extern int sftp_client_get (alloc_limits limits,
                            int *errn,
                            int *code,
                            t_uchar ** text,
                            int in_fd,
                            int out_fd,
                            int data_fd,
                            t_uchar * path);
extern int sftp_client_put (alloc_limits limits,
                            int *errn,
                            int *code,
                            t_uchar ** text,
                            int in_fd,
                            int out_fd,
                            int data_fd,
                            int connect_out,
                            t_uchar * path);
#endif  /* INCLUDE__SFTP_PROTOCOL__PROTOCOL_H */
