876eefd4 |
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 | * The main program in psftp.c. Called from main() in the platform- |
37 | * specific code, after doing any platform-specific initialisation. |
38 | */ |
39 | int psftp_main(int argc, char *argv[]); |
40 | |
41 | /* |
42 | * These functions are used by PSCP to transmit progress updates |
43 | * and error information to a GUI window managing it. This will |
44 | * probably only ever be supported on Windows, so these functions |
45 | * can safely be stubs on all other platforms. |
46 | */ |
47 | void gui_update_stats(char *name, unsigned long size, |
48 | int percentage, unsigned long elapsed, |
49 | unsigned long done, unsigned long eta, |
50 | unsigned long ratebs); |
51 | void gui_send_errcount(int list, int errs); |
52 | void gui_send_char(int is_stderr, int c); |
53 | void gui_enable(char *arg); |
54 | |
55 | /* |
56 | * It's likely that a given platform's implementation of file |
57 | * transfer utilities is going to want to do things with them that |
58 | * aren't present in stdio. Hence we supply an alternative |
59 | * abstraction for file access functions. |
60 | * |
61 | * This abstraction tells you the size and access times when you |
62 | * open an existing file (platforms may choose the meaning of the |
63 | * file times if it's not clear; whatever they choose will be what |
64 | * PSCP sends to the server as mtime and atime), and lets you set |
65 | * the times when saving a new file. |
66 | * |
67 | * On the other hand, the abstraction is pretty simple: it supports |
68 | * only opening a file and reading it, or creating a file and |
69 | * writing it. (FIXME: to use this in PSFTP it will also need to |
70 | * support seeking to a starting point for restarted transfers.) |
71 | * None of this read-and-write, seeking-back-and-forth stuff. |
72 | */ |
73 | typedef struct RFile RFile; |
74 | typedef struct WFile WFile; |
75 | /* Output params size, mtime and atime can all be NULL if desired */ |
76 | RFile *open_existing_file(char *name, unsigned long *size, |
77 | unsigned long *mtime, unsigned long *atime); |
78 | /* Returns <0 on error, 0 on eof, or number of bytes read, as usual */ |
79 | int read_from_file(RFile *f, void *buffer, int length); |
80 | /* Closes and frees the RFile */ |
81 | void close_rfile(RFile *f); |
82 | WFile *open_new_file(char *name); |
83 | /* Returns <0 on error, 0 on eof, or number of bytes written, as usual */ |
84 | int write_to_file(WFile *f, void *buffer, int length); |
85 | void set_file_times(WFile *f, unsigned long mtime, unsigned long atime); |
86 | /* Closes and frees the WFile */ |
87 | void close_wfile(WFile *f); |
88 | |
89 | /* |
90 | * Determine the type of a file: nonexistent, file, directory or |
91 | * weird. `weird' covers anything else - named pipes, Unix sockets, |
92 | * device files, fish, badgers, you name it. Things marked `weird' |
93 | * will be skipped over in recursive file transfers, so the only |
94 | * real reason for not lumping them in with `nonexistent' is that |
95 | * it allows a slightly more sane error message. |
96 | */ |
97 | enum { |
98 | FILE_TYPE_NONEXISTENT, FILE_TYPE_FILE, FILE_TYPE_DIRECTORY, FILE_TYPE_WEIRD |
99 | }; |
100 | int file_type(char *name); |
101 | |
102 | /* |
103 | * Read all the file names out of a directory. |
104 | */ |
105 | typedef struct DirHandle DirHandle; |
106 | DirHandle *open_directory(char *name); |
107 | /* The string returned from this will need freeing if not NULL */ |
108 | char *read_filename(DirHandle *dir); |
109 | void close_directory(DirHandle *dir); |
110 | |
111 | /* |
112 | * Test a filespec to see whether it's a local wildcard or not. |
113 | * Return values: |
114 | * |
115 | * - WCTYPE_WILDCARD (this is a wildcard). |
116 | * - WCTYPE_FILENAME (this is a single file name). |
117 | * - WCTYPE_NONEXISTENT (whichever it was, nothing of that name exists). |
118 | * |
119 | * Some platforms may choose not to support local wildcards when |
120 | * they come from the command line; in this case they simply never |
121 | * return WCTYPE_WILDCARD, but still test the file's existence. |
122 | * (However, all platforms will probably want to support wildcards |
123 | * inside the PSFTP CLI.) |
124 | */ |
125 | enum { |
126 | WCTYPE_NONEXISTENT, WCTYPE_FILENAME, WCTYPE_WILDCARD |
127 | }; |
128 | int test_wildcard(char *name, int cmdline); |
129 | |
130 | /* |
131 | * Actually return matching file names for a local wildcard. |
132 | */ |
133 | typedef struct WildcardMatcher WildcardMatcher; |
134 | WildcardMatcher *begin_wildcard_matching(char *name); |
135 | /* The string returned from this will need freeing if not NULL */ |
136 | char *wildcard_get_filename(WildcardMatcher *dir); |
137 | void finish_wildcard_matching(WildcardMatcher *dir); |
138 | |
139 | /* |
140 | * Create a directory. Returns 0 on error, !=0 on success. |
141 | */ |
142 | int create_directory(char *name); |
143 | |
144 | /* |
145 | * Concatenate a directory name and a file name. The way this is |
146 | * done will depend on the OS. |
147 | */ |
148 | char *dir_file_cat(char *dir, char *file); |
149 | |
150 | #endif /* PUTTY_PSFTP_H */ |