]> asedeno.scripts.mit.edu Git - PuTTY.git/blob - psftp.h
New timing infrastructure. There's a new function schedule_timer()
[PuTTY.git] / psftp.h
1 /*
2  * psftp.h: interface between psftp.c / scp.c and each
3  * platform-specific SFTP module.
4  */
5
6 #ifndef PUTTY_PSFTP_H
7 #define PUTTY_PSFTP_H
8
9 /*
10  * psftp_getcwd returns the local current directory. The returned
11  * string must be freed by the caller.
12  */
13 char *psftp_getcwd(void);
14
15 /*
16  * psftp_lcd changes the local current directory. The return value
17  * is NULL on success, or else an error message which must be freed
18  * by the caller.
19  */
20 char *psftp_lcd(char *newdir);
21
22 /*
23  * Retrieve file times on a local file. Must return two unsigned
24  * longs in POSIX time_t format.
25  */
26 void get_file_times(char *filename, unsigned long *mtime,
27                     unsigned long *atime);
28
29 /*
30  * One iteration of the PSFTP event loop: wait for network data and
31  * process it, once.
32  */
33 int ssh_sftp_loop_iteration(void);
34
35 /*
36  * Read a command line for PSFTP from standard input. Caller must
37  * free.
38  */
39 char *ssh_sftp_get_cmdline(char *prompt);
40
41 /*
42  * The main program in psftp.c. Called from main() in the platform-
43  * specific code, after doing any platform-specific initialisation.
44  */
45 int psftp_main(int argc, char *argv[]);
46
47 /*
48  * These functions are used by PSCP to transmit progress updates
49  * and error information to a GUI window managing it. This will
50  * probably only ever be supported on Windows, so these functions
51  * can safely be stubs on all other platforms.
52  */
53 void gui_update_stats(char *name, unsigned long size,
54                       int percentage, unsigned long elapsed,
55                       unsigned long done, unsigned long eta,
56                       unsigned long ratebs);
57 void gui_send_errcount(int list, int errs);
58 void gui_send_char(int is_stderr, int c);
59 void gui_enable(char *arg);
60
61 /*
62  * It's likely that a given platform's implementation of file
63  * transfer utilities is going to want to do things with them that
64  * aren't present in stdio. Hence we supply an alternative
65  * abstraction for file access functions.
66  * 
67  * This abstraction tells you the size and access times when you
68  * open an existing file (platforms may choose the meaning of the
69  * file times if it's not clear; whatever they choose will be what
70  * PSCP sends to the server as mtime and atime), and lets you set
71  * the times when saving a new file.
72  * 
73  * On the other hand, the abstraction is pretty simple: it supports
74  * only opening a file and reading it, or creating a file and
75  * writing it. (FIXME: to use this in PSFTP it will also need to
76  * support seeking to a starting point for restarted transfers.)
77  * None of this read-and-write, seeking-back-and-forth stuff.
78  */
79 typedef struct RFile RFile;
80 typedef struct WFile WFile;
81 /* Output params size, mtime and atime can all be NULL if desired */
82 RFile *open_existing_file(char *name, unsigned long *size,
83                           unsigned long *mtime, unsigned long *atime);
84 /* Returns <0 on error, 0 on eof, or number of bytes read, as usual */
85 int read_from_file(RFile *f, void *buffer, int length);
86 /* Closes and frees the RFile */
87 void close_rfile(RFile *f);
88 WFile *open_new_file(char *name);
89 /* Returns <0 on error, 0 on eof, or number of bytes written, as usual */
90 int write_to_file(WFile *f, void *buffer, int length);
91 void set_file_times(WFile *f, unsigned long mtime, unsigned long atime);
92 /* Closes and frees the WFile */
93 void close_wfile(WFile *f);
94
95 /*
96  * Determine the type of a file: nonexistent, file, directory or
97  * weird. `weird' covers anything else - named pipes, Unix sockets,
98  * device files, fish, badgers, you name it. Things marked `weird'
99  * will be skipped over in recursive file transfers, so the only
100  * real reason for not lumping them in with `nonexistent' is that
101  * it allows a slightly more sane error message.
102  */
103 enum {
104     FILE_TYPE_NONEXISTENT, FILE_TYPE_FILE, FILE_TYPE_DIRECTORY, FILE_TYPE_WEIRD
105 };
106 int file_type(char *name);
107
108 /*
109  * Read all the file names out of a directory.
110  */
111 typedef struct DirHandle DirHandle;
112 DirHandle *open_directory(char *name);
113 /* The string returned from this will need freeing if not NULL */
114 char *read_filename(DirHandle *dir);
115 void close_directory(DirHandle *dir);
116
117 /*
118  * Test a filespec to see whether it's a local wildcard or not.
119  * Return values:
120  * 
121  *  - WCTYPE_WILDCARD (this is a wildcard).
122  *  - WCTYPE_FILENAME (this is a single file name).
123  *  - WCTYPE_NONEXISTENT (whichever it was, nothing of that name exists).
124  * 
125  * Some platforms may choose not to support local wildcards when
126  * they come from the command line; in this case they simply never
127  * return WCTYPE_WILDCARD, but still test the file's existence.
128  * (However, all platforms will probably want to support wildcards
129  * inside the PSFTP CLI.)
130  */
131 enum {
132     WCTYPE_NONEXISTENT, WCTYPE_FILENAME, WCTYPE_WILDCARD
133 };
134 int test_wildcard(char *name, int cmdline);
135
136 /*
137  * Actually return matching file names for a local wildcard.
138  */
139 typedef struct WildcardMatcher WildcardMatcher;
140 WildcardMatcher *begin_wildcard_matching(char *name);
141 /* The string returned from this will need freeing if not NULL */
142 char *wildcard_get_filename(WildcardMatcher *dir);
143 void finish_wildcard_matching(WildcardMatcher *dir);
144
145 /*
146  * Create a directory. Returns 0 on error, !=0 on success.
147  */
148 int create_directory(char *name);
149
150 /*
151  * Concatenate a directory name and a file name. The way this is
152  * done will depend on the OS.
153  */
154 char *dir_file_cat(char *dir, char *file);
155
156 #endif /* PUTTY_PSFTP_H */