Mercurial > gftp.yaz
annotate lib/gftp.h @ 944:5b681cba67b2
2008-01-24 Brian Masney <masneyb@gftp.org>
* lib/gftp.h lib/rfc959.c lib/protocols.c lib/misc.c - don't store
the structure from getaddrinfo()/gethostbyname() in the
gftp_request structure. Instead, store the address of the current
server in a separate pointer.
author | masneyb |
---|---|
date | Thu, 24 Jan 2008 23:31:26 +0000 |
parents | 7b5aa0420fe2 |
children | c7d7a081cd9c |
rev | line source |
---|---|
1 | 1 /*****************************************************************************/ |
2 /* gftp.h - include file for the whole ftp program */ | |
122 | 3 /* Copyright (C) 1998-2003 Brian Masney <masneyb@gftp.org> */ |
1 | 4 /* */ |
5 /* This program is free software; you can redistribute it and/or modify */ | |
6 /* it under the terms of the GNU General Public License as published by */ | |
7 /* the Free Software Foundation; either version 2 of the License, or */ | |
8 /* (at your option) any later version. */ | |
9 /* */ | |
10 /* This program is distributed in the hope that it will be useful, */ | |
11 /* but WITHOUT ANY WARRANTY; without even the implied warranty of */ | |
12 /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ | |
13 /* GNU General Public License for more details. */ | |
14 /* */ | |
15 /* You should have received a copy of the GNU General Public License */ | |
16 /* along with this program; if not, write to the Free Software */ | |
17 /* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ | |
18 /*****************************************************************************/ | |
19 | |
33 | 20 /* $Id$ */ |
21 | |
1 | 22 #ifndef __GFTP_H |
23 #define __GFTP_H | |
24 | |
548 | 25 #ifndef _GNU_SOURCE |
26 #define _GNU_SOURCE | |
27 #endif | |
28 | |
1 | 29 #ifdef HAVE_CONFIG_H |
30 #include "config.h" | |
31 #endif | |
32 | |
435 | 33 /* *BSD include 64bit off_t but _LARGEFILE_SOURCE is not defined. */ |
34 #if defined (SIZEOF_OFF_T) && SIZEOF_OFF_T > 4 && !defined (_LARGEFILE_SOURCE) | |
423 | 35 #define _LARGEFILE_SOURCE 1 |
36 #endif | |
37 | |
437 | 38 #if defined (_LARGEFILE_SOURCE) && !defined (_LARGEFILE64_SOURCE) |
39 #define _LARGEFILE64_SOURCE 1 | |
40 #endif | |
41 | |
1 | 42 #include <sys/types.h> |
43 #include <sys/stat.h> | |
44 #include <sys/socket.h> | |
45 #include <sys/time.h> | |
46 #ifndef TIOCGWINSZ | |
47 #include <sys/ioctl.h> | |
48 #endif | |
49 #include <sys/wait.h> | |
50 #include <sys/utsname.h> | |
51 #include <netinet/in.h> | |
52 #include <arpa/inet.h> | |
53 #include <glib.h> | |
54 #include <limits.h> | |
55 #include <netdb.h> | |
56 #include <stdio.h> | |
57 #include <stdarg.h> | |
58 #include <stdlib.h> | |
59 #include <errno.h> | |
60 #include <fcntl.h> | |
61 #include <unistd.h> | |
62 #include <ctype.h> | |
63 #include <time.h> | |
64 #include <utime.h> | |
65 #include <signal.h> | |
66 #include <termios.h> | |
67 #include <pwd.h> | |
68 #include <setjmp.h> | |
69 #include <dirent.h> | |
70 #include <grp.h> | |
71 #include <math.h> | |
72 | |
325 | 73 #ifdef HAVE_STDINT_H |
74 #include <stdint.h> | |
75 #endif | |
76 | |
460 | 77 #ifdef HAVE_INTTYPES_H |
78 #include <inttypes.h> | |
79 #endif | |
80 | |
1 | 81 #ifdef HAVE_STRING_H |
82 #include <string.h> | |
83 #else | |
84 #include <strings.h> | |
85 #endif | |
86 | |
168 | 87 #ifdef USE_SSL |
88 #include <openssl/bio.h> | |
89 #include <openssl/err.h> | |
90 #include <openssl/rand.h> | |
91 #include <openssl/ssl.h> | |
92 #include <openssl/x509v3.h> | |
93 #endif | |
94 | |
1 | 95 #ifdef ENABLE_NLS |
96 #include <libintl.h> | |
97 #include <locale.h> | |
98 #define _(String) gettext (String) | |
99 #else | |
100 #define _(String) String | |
101 #endif | |
102 #define N_(String) String | |
103 | |
104 #ifndef AF_LOCAL | |
105 #define AF_LOCAL AF_UNIX | |
106 #endif | |
107 | |
351 | 108 /* Solaris needs this included for major()/minor() */ |
109 #ifdef HAVE_SYS_MKDEV_H | |
110 #include <sys/mkdev.h> | |
111 #endif | |
112 | |
48 | 113 /* We need the major() and minor() macros in the user interface. If they aren't |
114 defined by the system, we'll just define them here. */ | |
115 #ifndef major | |
116 #warning major macro was not defined by the system. Defining one that is probably wrong for your system | |
117 #define major(dev) (((dev) >> 8) & 0xff) | |
118 #endif | |
119 | |
120 #ifndef minor | |
121 #warning minor macro was not defined by the system. Defining one that is probably wrong for your system | |
122 #define minor(dev) ((dev) & 0xff) | |
123 #endif | |
124 | |
201 | 125 #ifdef WITH_DMALLOC |
126 | |
127 #undef g_malloc | |
128 #define g_malloc(size) \ | |
129 _malloc_leap(__FILE__, __LINE__, size) | |
130 | |
131 #undef g_malloc0 | |
132 #define g_malloc0(size) \ | |
133 _calloc_leap(__FILE__, __LINE__, 1, size) | |
134 | |
135 #undef g_realloc | |
136 #define g_realloc(ptr, size) \ | |
137 _realloc_leap(__FILE__, __LINE__, ptr, size) | |
138 | |
139 #undef g_strdup | |
140 #define g_strdup(str) \ | |
141 _strdup_leap(__FILE__, __LINE__, str) | |
142 | |
143 #undef g_free | |
144 #define g_free(ptr) \ | |
145 _free_leap(__FILE__, __LINE__, ptr) | |
146 | |
1 | 147 #include <dmalloc.h> |
201 | 148 |
1 | 149 #endif |
150 | |
338 | 151 #ifdef __GNUC__ |
152 # define GFTP_LOG_FUNCTION_ATTRIBUTES __attribute__((format(printf, 3, 4))) | |
153 #else | |
154 # define GFTP_LOG_FUNCTION_ATTRIBUTES | |
155 #endif | |
156 | |
944 | 157 #if defined (HAVE_GETADDRINFO) && defined (HAVE_GAI_STRERROR) |
158 # define HAVE_IPV6 | |
159 #endif | |
160 | |
649 | 161 #if defined (_LARGEFILE_SOURCE) && !defined (__hppa__) && !defined (__hppa) |
532 | 162 #define GFTP_OFF_T_HEX_PRINTF_MOD "%llx" |
163 #define GFTP_OFF_T_INTL_PRINTF_MOD "%'lld" | |
164 #define GFTP_OFF_T_PRINTF_MOD "%lld" | |
165 #define GFTP_OFF_T_11PRINTF_MOD "%11lld" | |
166 #define gftp_parse_file_size(str) strtoll (str, NULL, 10) | |
926 | 167 #define GFTP_OFF_T_PRINTF_CONVERSION long long |
516 | 168 #else |
532 | 169 #define GFTP_OFF_T_HEX_PRINTF_MOD "%lx" |
170 #define GFTP_OFF_T_INTL_PRINTF_MOD "%'ld" | |
171 #define GFTP_OFF_T_PRINTF_MOD "%ld" | |
172 #define GFTP_OFF_T_11PRINTF_MOD "%11ld" | |
173 #define gftp_parse_file_size(str) strtol (str, NULL, 10) | |
926 | 174 #define GFTP_OFF_T_PRINTF_CONVERSION off_t |
516 | 175 #endif |
176 | |
91 | 177 /* Server types (used by FTP protocol from SYST command) */ |
122 | 178 #define GFTP_DIRTYPE_UNIX 1 |
179 #define GFTP_DIRTYPE_EPLF 2 | |
180 #define GFTP_DIRTYPE_CRAY 3 | |
181 #define GFTP_DIRTYPE_NOVELL 4 | |
182 #define GFTP_DIRTYPE_DOS 5 | |
183 #define GFTP_DIRTYPE_VMS 6 | |
184 #define GFTP_DIRTYPE_OTHER 7 | |
358 | 185 #define GFTP_DIRTYPE_MVS 8 |
91 | 186 |
84 | 187 /* Error types */ |
341 | 188 #define GFTP_ERETRYABLE -1 /* Temporary failure. The GUI |
189 should wait briefly */ | |
190 #define GFTP_EFATAL -2 /* Fatal error */ | |
191 #define GFTP_ERETRYABLE_NO_WAIT -3 /* Temporary failure. The GUI | |
192 should not wait and should | |
193 reconnect */ | |
426 | 194 #define GFTP_ENOTRANS -4 /* Custom error. This is |
195 returned when a FXP transfer | |
196 is requested */ | |
442 | 197 #define GFTP_ETIMEDOUT -5 /* Connected timed out */ |
84 | 198 |
1 | 199 /* Some general settings */ |
200 #define BASE_CONF_DIR "~/.gftp" | |
201 #define CONFIG_FILE BASE_CONF_DIR "/gftprc" | |
202 #define BOOKMARKS_FILE BASE_CONF_DIR "/bookmarks" | |
203 #define LOG_FILE BASE_CONF_DIR "/gftp.log" | |
204 #define MAX_HIST_LEN 10 | |
356 | 205 #define GFTP_URL_USAGE "[[protocol://][user[:pass]@]site[:port][/directory]]" |
1 | 206 |
207 typedef enum gftp_logging_level_tag | |
208 { | |
209 gftp_logging_send, | |
210 gftp_logging_recv, | |
211 gftp_logging_error, | |
354 | 212 gftp_logging_misc, |
213 gftp_logging_misc_nolog /* Log to the screen, but don't log to disk */ | |
1 | 214 } gftp_logging_level; |
215 | |
216 typedef struct gftp_file_tag gftp_file; | |
217 | |
218 #define GFTP_TRANS_ACTION_OVERWRITE 1 | |
219 #define GFTP_TRANS_ACTION_RESUME 2 | |
220 #define GFTP_TRANS_ACTION_SKIP 3 | |
221 | |
16 | 222 #define GFTP_SORT_COL_FILE 1 |
223 #define GFTP_SORT_COL_SIZE 2 | |
224 #define GFTP_SORT_COL_USER 3 | |
225 #define GFTP_SORT_COL_GROUP 4 | |
226 #define GFTP_SORT_COL_DATETIME 5 | |
227 #define GFTP_SORT_COL_ATTRIBS 6 | |
228 | |
499 | 229 #define GFTP_IS_SPECIAL_DEVICE(mode) (S_ISBLK (mode) || S_ISCHR (mode)) |
230 | |
1 | 231 struct gftp_file_tag |
232 { | |
765 | 233 /*@null@*/ char *file, /* Our filename */ |
234 *user, /* User that owns it */ | |
235 *group, /* Group that owns it */ | |
236 *destfile; /* Full pathname to the destination for the | |
1 | 237 file transfer */ |
122 | 238 |
239 int fd; /* Already open fd for this file */ | |
240 /* FIXME - add fd_open function */ | |
241 | |
1 | 242 time_t datetime; /* File date and time */ |
14
83090328581e
* More largefile support. Hopefully all that is left is the configure stuff
masneyb
parents:
1
diff
changeset
|
243 off_t size, /* Size of the file */ |
83090328581e
* More largefile support. Hopefully all that is left is the configure stuff
masneyb
parents:
1
diff
changeset
|
244 startsize; /* Size to start the transfer at */ |
499 | 245 mode_t st_mode; /* File attributes */ |
852 | 246 |
247 dev_t st_dev; /* The device and associated inode. These */ | |
248 ino_t st_ino; /* two fields are used for detecting loops */ | |
249 /* with symbolic links. */ | |
250 | |
499 | 251 unsigned int selected : 1, /* Is this file selected? */ |
1 | 252 was_sel : 1, /* Was this file selected before */ |
253 shown : 1, /* Is this file shown? */ | |
254 done_view : 1, /* View the file when done transfering? */ | |
255 done_edit : 1, /* Edit the file when done transfering? */ | |
256 done_rm : 1, /* Remove the file when done */ | |
257 transfer_done : 1, /* Is current file transfer done? */ | |
862 | 258 retry_transfer : 1, /* Is current file transfer done? */ |
916 | 259 exists_other_side : 1, /* The file exists on the other side |
260 during the file transfer */ | |
261 filename_utf8_encoded : 1; /* Is the filename properly UTF8 | |
262 encoded? */ | |
263 | |
1 | 264 char transfer_action; /* See the GFTP_TRANS_ACTION_* vars above */ |
765 | 265 /*@null@*/ void *user_data; |
1 | 266 }; |
267 | |
268 | |
269 typedef struct gftp_proxy_hosts_tag | |
270 { | |
303 | 271 /* FIXME - add IPV6 stuff here */ |
122 | 272 |
273 gint32 ipv4_network_address, | |
1 | 274 ipv4_netmask; |
275 char *domain; | |
276 } gftp_proxy_hosts; | |
277 | |
136 | 278 |
279 /* Note, these numbers must match up to the index number in config_file.c | |
280 in the declaration of gftp_option_types */ | |
281 typedef enum | |
282 { | |
283 gftp_option_type_text = 0, | |
284 gftp_option_type_textcombo = 1, | |
285 gftp_option_type_textcomboedt = 2, | |
286 gftp_option_type_hidetext = 3, | |
287 gftp_option_type_int = 4, | |
288 gftp_option_type_checkbox = 5, | |
289 gftp_option_type_intcombo = 6, | |
290 gftp_option_type_float = 7, | |
291 gftp_option_type_color = 8, | |
292 gftp_option_type_notebook = 9 | |
293 } gftp_option_type_enum; | |
294 | |
295 | |
296 #define GFTP_PORT_GTK (1 << 1) | |
297 #define GFTP_PORT_TEXT (1 << 2) | |
298 #define GFTP_PORT_ALL (GFTP_PORT_GTK | GFTP_PORT_TEXT) | |
299 | |
300 | |
301 typedef struct gftp_config_list_vars_tag | |
302 { | |
303 char *key; | |
304 void * (*read_func) (char *buf, int line); | |
305 void (*write_func) (FILE *fd, void *data); | |
306 GList * list; | |
307 unsigned int num_items; | |
308 char *header; | |
309 } gftp_config_list_vars; | |
310 | |
311 | |
201 | 312 #define GFTP_CVARS_FLAGS_DYNMEM (1 << 1) |
313 #define GFTP_CVARS_FLAGS_DYNLISTMEM (1 << 2) | |
227 | 314 #define GFTP_CVARS_FLAGS_SHOW_BOOKMARK (1 << 3) |
136 | 315 |
316 typedef struct gftp_config_vars_tag | |
317 { | |
765 | 318 /*@null@*/ char *key, /* variable name */ |
319 *description; /* How this field will show up in the dialog */ | |
136 | 320 int otype; /* Type of option this is */ |
765 | 321 /*@null@*/ void *value; |
322 /*@null@*/ void *listdata; /* For options that have several different | |
136 | 323 options, this is a list of all the options. |
324 Each option_type that uses this will use this | |
325 field differently */ | |
326 int flags; /* See GFTP_CVARS_FLAGS_* above */ | |
765 | 327 /*@null@*/ char *comment; /* Comment to write out to the config file */ |
136 | 328 int ports_shown; /* What ports of gFTP is this option shown in */ |
765 | 329 /*@null@*/ void *user_data; /* Data that the GUI can store here (Widget in gtk+) */ |
136 | 330 } gftp_config_vars; |
331 | |
332 | |
333 typedef struct gftp_option_type_tag | |
334 { | |
335 int (*read_function) (char *str, gftp_config_vars * cv, int line); | |
765 | 336 int (*write_function) (gftp_config_vars * cv, /*@out@*/ char *buf, |
337 size_t buflen, int to_config_file); | |
207 | 338 void (*copy_function) (gftp_config_vars * cv, gftp_config_vars * dest_cv); |
227 | 339 int (*compare_function) (gftp_config_vars * cv1, gftp_config_vars * cv2); |
229 | 340 void *(*ui_print_function) (gftp_config_vars * cv, void *user_data, void *value); |
136 | 341 void (*ui_save_function) (gftp_config_vars * cv, void *user_data); |
139 | 342 void (*ui_cancel_function) (gftp_config_vars * cv, void *user_data); |
136 | 343 void *user_data; |
344 } gftp_option_type_var; | |
345 | |
346 | |
347 #define GFTP_TEXTCOMBOEDT_EDITABLE (1 << 0) | |
348 | |
349 typedef struct gftp_textcomboedt_data_tag | |
350 { | |
765 | 351 /*@null@*/ char *description, |
352 *text; | |
136 | 353 int flags; |
354 } gftp_textcomboedt_data; | |
355 | |
356 | |
1 | 357 typedef struct gftp_request_tag gftp_request; |
358 | |
186 | 359 typedef void (*gftp_logging_func) ( gftp_logging_level level, |
765 | 360 /*@null@*/ gftp_request * request, |
186 | 361 const char *string, ... ); |
362 | |
570 | 363 #define GFTP_ANONYMOUS_USER "anonymous" |
555 | 364 #define gftp_need_username(request) ((request)->need_username && ((request)->username == NULL || *(request)->username == '\0')) |
570 | 365 #define gftp_need_password(request) ((request)->need_password && (request)->username != NULL && *(request)->username != '\0' && strcasecmp ((request)->username, GFTP_ANONYMOUS_USER) != 0 && ((request)->password == NULL || *(request)->password == '\0')) |
553 | 366 |
1 | 367 struct gftp_request_tag |
368 { | |
369 int protonum; /* Current number of the protocol this is | |
370 set to */ | |
371 char *hostname, /* Hostname we will connect to */ | |
372 *username, /* Username for host*/ | |
373 *password, /* Password for host */ | |
374 *account, /* Account for host (FTP only) */ | |
375 *directory, /* Current working directory */ | |
376 *url_prefix, /* URL Prefix (ex: ftp) */ | |
377 *last_ftp_response, /* Last response from server */ | |
378 *last_dir_entry; /* Last dir entry from server */ | |
379 size_t last_dir_entry_len; /* Length of last_dir_entry */ | |
380 | |
122 | 381 unsigned int port; /* Port of remote site */ |
1 | 382 |
169 | 383 int datafd, /* Data connection */ |
58 | 384 cachefd; /* For the directory cache */ |
1 | 385 int wakeup_main_thread[2]; /* FD that gets written to by the threads |
386 to wakeup the parent */ | |
122 | 387 |
1 | 388 #if defined (HAVE_GETADDRINFO) && defined (HAVE_GAI_STRERROR) |
944 | 389 void *remote_addr; |
390 size_t remote_addr_len; | |
1 | 391 #endif |
944 | 392 int ai_family; |
1 | 393 |
122 | 394 int server_type; /* The type of server we are connected to. |
395 See GFTP_DIRTYPE_* above */ | |
944 | 396 unsigned int use_proxy : 1, |
1 | 397 always_connected : 1, |
398 need_hostport : 1, | |
553 | 399 need_username : 1, |
400 need_password : 1, | |
1 | 401 use_cache : 1, /* Enable or disable the cache */ |
402 cached : 1, /* Is this directory listing cached? */ | |
41 | 403 cancel : 1, /* If a signal is received, should |
404 we cancel this operation */ | |
832 | 405 stopable : 1, |
879 | 406 refreshing : 1, |
832 | 407 use_local_encoding : 1; |
1 | 408 |
409 off_t gotbytes; | |
410 | |
411 void *protocol_data; | |
412 | |
413 gftp_logging_func logging_function; | |
414 void *user_data; | |
415 | |
173 | 416 int (*init) ( gftp_request * request ); |
309 | 417 void (*copy_param_options) ( gftp_request * dest_request, |
418 gftp_request * src_request ); | |
168 | 419 ssize_t (*read_function) ( gftp_request * request, |
420 void *ptr, | |
421 size_t size, | |
422 int fd ); | |
423 ssize_t (*write_function) ( gftp_request * request, | |
424 const char *ptr, | |
425 size_t size, | |
426 int fd ); | |
1 | 427 void (*destroy) ( gftp_request * request ); |
428 int (*connect) ( gftp_request * request ); | |
168 | 429 int (*post_connect) ( gftp_request * request ); |
1 | 430 void (*disconnect) ( gftp_request * request ); |
58 | 431 off_t (*get_file) ( gftp_request * request, |
1 | 432 const char *filename, |
433 off_t startsize ); | |
434 int (*put_file) ( gftp_request * request, | |
435 const char *filename, | |
436 off_t startsize, | |
437 off_t totalsize ); | |
765 | 438 off_t (*transfer_file) ( gftp_request * fromreq, |
1 | 439 const char *fromfile, |
440 off_t fromsize, | |
441 gftp_request * toreq, | |
442 const char *tofile, | |
443 off_t tosize ); | |
58 | 444 ssize_t (*get_next_file_chunk) ( gftp_request * request, |
1 | 445 char *buf, |
446 size_t size ); | |
58 | 447 ssize_t (*put_next_file_chunk) ( gftp_request * request, |
1 | 448 char *buf, |
449 size_t size ); | |
450 int (*end_transfer) ( gftp_request * request ); | |
40 | 451 int (*abort_transfer) ( gftp_request * request ); |
520 | 452 int (*stat_filename) ( gftp_request * request, |
453 const char *filename, | |
787 | 454 mode_t * mode, |
455 off_t * filesize ); | |
1 | 456 int (*list_files) ( gftp_request * request ); |
457 int (*get_next_file) ( gftp_request * request, | |
458 gftp_file *fle, | |
58 | 459 int fd ); |
485 | 460 ssize_t (*get_next_dirlist_line) ( gftp_request * request, |
461 int fd, | |
462 char *buf, | |
463 size_t buflen ); | |
1 | 464 off_t (*get_file_size) ( gftp_request * request, |
465 const char *filename ); | |
466 int (*chdir) ( gftp_request * request, | |
467 const char *directory ); | |
468 int (*rmdir) ( gftp_request * request, | |
469 const char *directory ); | |
470 int (*rmfile) ( gftp_request * request, | |
471 const char *filename ); | |
472 int (*mkdir) ( gftp_request * request, | |
473 const char *directory ); | |
474 int (*rename) ( gftp_request * request, | |
475 const char *oldname, | |
476 const char *newname ); | |
477 int (*chmod) ( gftp_request * request, | |
478 const char *filename, | |
499 | 479 mode_t mode ); |
1 | 480 int (*set_file_time) ( gftp_request * request, |
481 const char *filename, | |
482 time_t datettime ); | |
483 int (*site) ( gftp_request * request, | |
478 | 484 int specify_site, |
1 | 485 const char *filename ); |
486 int (*parse_url) ( gftp_request * request, | |
487 const char *url ); | |
177 | 488 int (*set_config_options) ( gftp_request * request ); |
63 | 489 void (*swap_socks) ( gftp_request * dest, |
490 gftp_request * source ); | |
1 | 491 |
136 | 492 gftp_config_vars * local_options_vars; |
493 int num_local_options_vars; | |
494 GHashTable * local_options_hash; | |
168 | 495 #ifdef USE_SSL |
496 SSL * ssl; | |
497 #endif | |
184 | 498 |
499 #if GLIB_MAJOR_VERSION > 1 | |
899 | 500 GIConv iconv_to, iconv_from; |
501 unsigned int iconv_from_initialized : 1, | |
502 iconv_to_initialized : 1; | |
842 | 503 char *iconv_charset; |
184 | 504 #endif |
1 | 505 }; |
506 | |
507 | |
136 | 508 typedef struct gftp_transfer_tag |
1 | 509 { |
510 gftp_request * fromreq, | |
511 * toreq; | |
512 | |
305 | 513 unsigned int cancel : 1, |
1 | 514 ready : 1, |
515 started : 1, | |
516 done : 1, | |
517 show : 1, | |
518 stalled : 1, | |
303 | 519 conn_error_no_timeout : 1, |
1 | 520 next_file : 1, |
14
83090328581e
* More largefile support. Hopefully all that is left is the configure stuff
masneyb
parents:
1
diff
changeset
|
521 skip_file : 1; |
1 | 522 |
523 struct timeval starttime, | |
524 lasttime; | |
525 | |
526 double kbs; | |
527 | |
528 GList * files, | |
529 * curfle, | |
530 * updfle; | |
531 | |
19 | 532 long numfiles, |
533 numdirs, | |
534 current_file_number, | |
535 current_file_retries; | |
1 | 536 |
537 off_t curtrans, /* Current transfered bytes for this file */ | |
377 | 538 tot_file_trans, /* Total number of bytes in the file being |
539 transferred */ | |
1 | 540 curresumed, /* Resumed bytes for this file */ |
541 trans_bytes, /* Amount of data transfered for entire | |
542 transfer */ | |
543 total_bytes, /* Grand total bytes for whole transfer */ | |
544 resumed_bytes; /* Grand total of resumed bytes for whole | |
545 transfer */ | |
546 | |
547 void * fromwdata, | |
548 * towdata; | |
549 | |
122 | 550 GStaticMutex statmutex, |
551 structmutex; | |
552 | |
125 | 553 void *user_data; |
876 | 554 void *thread_id; |
1 | 555 void *clist; |
136 | 556 } gftp_transfer; |
1 | 557 |
558 | |
559 typedef struct gftp_log_tag | |
560 { | |
561 char *msg; | |
562 gftp_logging_level type; | |
563 } gftp_log; | |
564 | |
565 | |
566 typedef struct supported_gftp_protocols_tag | |
567 { | |
765 | 568 /*@null@*/ char *name; /* Description of protocol */ |
569 /*@null@*/ int (*init) (gftp_request * request); /* Init function */ | |
570 /*@null@*/ void (*register_options) (void); /* Protocol options */ | |
571 /*@null@*/ char *url_prefix; /* URL Prefix */ | |
542 | 572 unsigned int default_port; /* Default port */ |
341 | 573 unsigned int shown : 1, /* Whether this protocol is |
122 | 574 shown or not to the user in |
575 the protocol dropdown box */ | |
341 | 576 use_threads : 1; /* Whether or not operations in |
577 this protocol should use | |
578 threads */ | |
1 | 579 } supported_gftp_protocols; |
580 | |
581 | |
122 | 582 typedef struct gftp_bookmarks_tag gftp_bookmarks_var; |
1 | 583 |
584 struct gftp_bookmarks_tag | |
585 { | |
609 | 586 char *path, /* Path */ |
587 *oldpath, /* Old path name */ | |
588 *hostname, /* Our actual internet hostname */ | |
1 | 589 *protocol, /* Protocol we will connect through */ |
590 *remote_dir, /* Initial directory */ | |
591 *local_dir, /* Init local directory */ | |
592 *user, /* Username to log in as */ | |
593 *pass, /* Our password */ | |
594 *acct; /* Account */ | |
595 | |
596 unsigned int port, /* The port we will connect to */ | |
597 isfolder : 1, /* If this is set, then the children field can | |
598 be non-NULL */ | |
599 save_password : 1; /* Save this password */ | |
122 | 600 gftp_bookmarks_var *children, /* The children of this node. */ |
601 *prev, /* The parent of this node */ | |
602 *next; /* The next sibling of this node */ | |
1 | 603 gpointer cnode; |
604 | |
199 | 605 gftp_config_vars * local_options_vars; |
606 int num_local_options_vars; | |
607 GHashTable * local_options_hash; | |
1 | 608 }; |
609 | |
610 | |
611 typedef struct gftp_file_extensions_tag | |
612 { | |
613 char *ext, /* The file extension to register */ | |
614 *filename, /* The xpm file to display */ | |
615 *view_program, /* The program used to view this file */ | |
616 *ascii_binary; /* Is this a ASCII transfer or a BINARY transfer */ | |
516 | 617 unsigned int stlen; /* How long is the file extension. */ |
1 | 618 } gftp_file_extensions; |
619 | |
620 | |
621 typedef struct gftp_color_tag | |
622 { | |
623 gushort red, | |
624 green, | |
625 blue; | |
626 } gftp_color; | |
627 | |
628 | |
58 | 629 typedef struct gftp_getline_buffer_tag |
630 { | |
631 char *buffer, | |
632 *curpos; | |
633 size_t max_bufsize, | |
634 cur_bufsize; | |
179 | 635 unsigned int eof : 1; |
58 | 636 } gftp_getline_buffer; |
637 | |
126 | 638 |
122 | 639 /* Global config options. These are defined in options.h */ |
765 | 640 /*@null@*/ extern GList * gftp_file_transfers, * gftp_file_transfer_logs, |
641 * gftp_options_list; | |
642 /*@null@*/ extern GHashTable * gftp_global_options_htable, * gftp_bookmarks_htable, | |
643 * gftp_config_list_htable; | |
644 /*@null@*/ extern gftp_bookmarks_var * gftp_bookmarks; | |
645 /*@null@*/ extern FILE * gftp_logfd; | |
122 | 646 extern gftp_config_vars gftp_global_config_vars[]; |
1 | 647 extern supported_gftp_protocols gftp_protocols[]; |
122 | 648 extern char gftp_version[]; |
201 | 649 extern int gftp_configuration_changed; |
122 | 650 |
651 /* This is defined in config_file.c */ | |
652 | |
653 extern gftp_option_type_var gftp_option_types[]; | |
1 | 654 |
655 /* cache.c */ | |
182 | 656 void gftp_generate_cache_description ( gftp_request * request, |
765 | 657 /*@out@*/ char *description, |
182 | 658 size_t len, |
659 int ignore_directory ); | |
660 | |
58 | 661 int gftp_new_cache_entry ( gftp_request * request ); |
1 | 662 |
58 | 663 int gftp_find_cache_entry ( gftp_request * request ); |
1 | 664 |
665 void gftp_clear_cache_files ( void ); | |
666 | |
47 | 667 void gftp_delete_cache_entry ( gftp_request * request, |
182 | 668 char *descr, |
47 | 669 int ignore_directory ); |
1 | 670 |
671 /* config_file.c */ | |
198 | 672 int gftp_config_parse_args ( char *str, |
673 int numargs, | |
674 int lineno, | |
765 | 675 /*@out@*/ char **first, |
198 | 676 ... ); |
677 | |
122 | 678 void gftp_add_bookmark ( gftp_bookmarks_var * newentry ); |
679 | |
124 | 680 void gftp_read_config_file ( char *global_data_path ); |
1 | 681 |
122 | 682 void gftp_write_bookmarks_file ( void ); |
1 | 683 |
684 void gftp_write_config_file ( void ); | |
685 | |
122 | 686 GHashTable * build_bookmarks_hash_table ( gftp_bookmarks_var * entry ); |
687 | |
688 void print_bookmarks ( gftp_bookmarks_var * bookmarks ); | |
689 | |
374 | 690 void gftp_lookup_global_option ( const char * key, |
765 | 691 /*@out@*/ void *value ); |
26 | 692 |
122 | 693 void gftp_lookup_request_option ( gftp_request * request, |
374 | 694 const char * key, |
765 | 695 /*@out@*/ void *value ); |
696 | |
1 | 697 |
229 | 698 void gftp_lookup_bookmark_option ( gftp_bookmarks_var * bm, |
374 | 699 const char * key, |
229 | 700 void *value ); |
701 | |
374 | 702 void gftp_set_global_option ( const char * key, |
227 | 703 const void *value ); |
122 | 704 |
705 void gftp_set_request_option ( gftp_request * request, | |
374 | 706 const char * key, |
229 | 707 const void *value ); |
708 | |
709 void gftp_set_bookmark_option ( gftp_bookmarks_var * bm, | |
374 | 710 const char * key, |
229 | 711 const void *value ); |
122 | 712 |
713 void gftp_register_config_vars ( gftp_config_vars *config_vars ); | |
1 | 714 |
201 | 715 void gftp_copy_local_options ( gftp_config_vars ** new_options_vars, |
716 GHashTable ** new_options_hash, | |
429 | 717 int *new_num_local_options_vars, |
201 | 718 gftp_config_vars * orig_options, |
719 int num_local_options_vars ); | |
720 | |
721 void gftp_config_free_options ( gftp_config_vars * options_vars, | |
722 GHashTable * options_hash, | |
723 int num_options_vars ); | |
724 | |
725 void gftp_bookmarks_destroy ( gftp_bookmarks_var * bookmarks ); | |
726 | |
218 | 727 void gftp_free_proxy_hosts ( GList * proxy_hosts ); |
728 | |
729 GList * gftp_copy_proxy_hosts ( GList * proxy_hosts ); | |
730 | |
1 | 731 /* misc.c */ |
765 | 732 /*@null@*/ char *insert_commas ( off_t number, |
1 | 733 char *dest_str, |
734 size_t dest_len ); | |
735 | |
736 char *alltrim ( char *str ); | |
737 | |
555 | 738 char *gftp_expand_path ( gftp_request * request, |
739 const char *src ); | |
1 | 740 |
741 void make_nonnull ( char **str ); | |
742 | |
821 | 743 int gftp_match_filespec ( gftp_request * request, |
744 const char *filename, | |
374 | 745 const char *filespec ); |
1 | 746 |
747 int gftp_parse_command_line ( int *argc, | |
748 char ***argv ); | |
749 | |
750 void gftp_usage ( void ); | |
751 | |
752 gint string_hash_compare ( gconstpointer path1, | |
753 gconstpointer path2 ); | |
754 | |
755 guint string_hash_function ( gconstpointer key ); | |
756 | |
852 | 757 gint uint_hash_compare ( gconstpointer path1, |
758 gconstpointer path2 ); | |
759 | |
760 guint uint_hash_function ( gconstpointer key ); | |
761 | |
1 | 762 void free_file_list ( GList * filelist ); |
763 | |
764 gftp_file * copy_fdata ( gftp_file * fle ); | |
765 | |
766 int compare_request ( gftp_request * request1, | |
767 gftp_request * request2, | |
768 int compare_dirs ); | |
769 | |
129 | 770 gftp_transfer * gftp_tdata_new ( void ); |
771 | |
1 | 772 void free_tdata ( gftp_transfer * tdata ); |
773 | |
368 | 774 gftp_request * gftp_copy_request ( gftp_request * req ); |
1 | 775 |
16 | 776 GList * gftp_sort_filelist ( GList * filelist, |
777 int column, | |
778 int asds ); | |
779 | |
830 | 780 char * gftp_gen_ls_string ( gftp_request * request, |
781 gftp_file * fle, | |
131 | 782 char *file_prefixstr, |
783 char *file_suffixstr ); | |
784 | |
168 | 785 char * base64_encode ( char *str ); |
786 | |
609 | 787 void gftp_free_bookmark ( gftp_bookmarks_var * entry, |
788 int free_node ); | |
199 | 789 |
201 | 790 void gftp_shutdown ( void ); |
199 | 791 |
207 | 792 GList * get_next_selection ( GList * selection, |
793 GList ** list, | |
794 int *curnum ); | |
795 | |
555 | 796 char * gftp_build_path ( gftp_request * request, |
797 const char *first_element, | |
227 | 798 ... ); |
799 | |
290 | 800 void gftp_locale_init ( void ); |
801 | |
330 | 802 char * gftp_scramble_password ( const char *password ); |
803 | |
804 char * gftp_descramble_password ( const char *password ); | |
805 | |
378 | 806 int gftp_get_transfer_action ( gftp_request * request, |
807 gftp_file * fle ); | |
808 | |
483 | 809 char * gftp_get_share_dir ( void ); |
810 | |
402 | 811 /* mkstemps.c */ |
812 int mkstemps ( char *template, | |
813 int suffix_len ); | |
814 | |
1 | 815 /* protocols.c */ |
816 #define GFTP_FTP_NUM 0 | |
389 | 817 #define GFTP_FTPS_NUM 1 |
818 #define GFTP_HTTP_NUM 2 | |
819 #define GFTP_HTTPS_NUM 3 | |
820 #define GFTP_LOCAL_NUM 4 | |
821 #define GFTP_SSHV2_NUM 5 | |
822 #define GFTP_BOOKMARK_NUM 6 | |
661 | 823 #define GFTP_FSP_NUM 7 |
122 | 824 |
1 | 825 #define GFTP_IS_CONNECTED(request) ((request) != NULL && \ |
169 | 826 ((request)->datafd > 0 || \ |
58 | 827 (request)->cached || \ |
828 (request)->always_connected)) | |
1 | 829 |
830 | |
173 | 831 int rfc959_init ( gftp_request * request ); |
1 | 832 |
122 | 833 void rfc959_register_module ( void ); |
834 | |
1 | 835 int rfc959_get_next_file ( gftp_request * request, |
836 gftp_file *fle, | |
58 | 837 int fd ); |
1 | 838 |
451 | 839 int rfc959_connect ( gftp_request * request ); |
840 | |
389 | 841 int ftps_init ( gftp_request * request ); |
842 | |
843 void ftps_register_module ( void ); | |
844 | |
173 | 845 int rfc2068_init ( gftp_request * request ); |
1 | 846 |
122 | 847 void rfc2068_register_module ( void ); |
848 | |
173 | 849 int https_init ( gftp_request * request ); |
168 | 850 |
851 void https_register_module ( void ); | |
852 | |
173 | 853 int local_init ( gftp_request * request ); |
1 | 854 |
122 | 855 void local_register_module ( void ); |
856 | |
173 | 857 int sshv2_init ( gftp_request * request ); |
1 | 858 |
122 | 859 void sshv2_register_module ( void ); |
860 | |
174 | 861 void ssl_register_module ( void ); |
862 | |
173 | 863 int bookmark_init ( gftp_request * request ); |
1 | 864 |
122 | 865 void bookmark_register_module ( void ); |
866 | |
661 | 867 int fsp_init ( gftp_request * request ); |
868 | |
869 void fsp_register_module ( void ); | |
870 | |
1 | 871 gftp_request *gftp_request_new ( void ); |
872 | |
67 | 873 void gftp_request_destroy ( gftp_request * request, |
874 int free_request ); | |
1 | 875 |
309 | 876 void gftp_copy_param_options ( gftp_request * dest_request, |
877 gftp_request * src_request ); | |
878 | |
598 | 879 void gftp_file_destroy ( gftp_file *file, |
880 int free_it ); | |
1 | 881 |
882 int gftp_connect ( gftp_request * request ); | |
883 | |
884 void gftp_disconnect ( gftp_request * request ); | |
885 | |
58 | 886 off_t gftp_get_file ( gftp_request * request, |
1 | 887 const char *filename, |
244 | 888 off_t startsize ); |
1 | 889 |
890 int gftp_put_file ( gftp_request * request, | |
891 const char *filename, | |
244 | 892 off_t startsize, |
893 off_t totalsize ); | |
1 | 894 |
261 | 895 off_t gftp_transfer_file ( gftp_request *fromreq, |
1 | 896 const char *fromfile, |
244 | 897 off_t fromsize, |
1 | 898 gftp_request *toreq, |
899 const char *tofile, | |
244 | 900 off_t tosize ); |
1 | 901 |
58 | 902 ssize_t gftp_get_next_file_chunk ( gftp_request * request, |
1 | 903 char *buf, |
904 size_t size ); | |
905 | |
58 | 906 ssize_t gftp_put_next_file_chunk ( gftp_request * request, |
1 | 907 char *buf, |
908 size_t size ); | |
909 | |
910 int gftp_list_files ( gftp_request * request ); | |
911 | |
765 | 912 /*@null@*/ char * gftp_string_to_utf8 ( gftp_request * request, |
838 | 913 const char *str, |
914 size_t *dest_len ); | |
291 | 915 |
765 | 916 /*@null@*/ char * gftp_string_from_utf8 ( gftp_request * request, |
845 | 917 int force_local, |
918 const char *str, | |
919 size_t *dest_len ); | |
920 | |
921 /*@null@*/ char * gftp_filename_to_utf8 ( gftp_request * request, | |
922 const char *str, | |
923 size_t *dest_len ); | |
924 | |
925 /*@null@*/ char * gftp_filename_from_utf8 ( gftp_request * request, | |
838 | 926 const char *str, |
927 size_t *dest_len ); | |
186 | 928 |
87 | 929 int gftp_parse_bookmark ( gftp_request * request, |
243 | 930 gftp_request * local_request, |
275 | 931 const char * bookmark, |
932 int *refresh_local ); | |
87 | 933 |
1 | 934 int gftp_parse_url ( gftp_request * request, |
935 const char *url ); | |
936 | |
937 int gftp_get_next_file ( gftp_request * request, | |
377 | 938 const char *filespec, |
1 | 939 gftp_file *fle ); |
940 | |
941 int gftp_end_transfer ( gftp_request * request ); | |
942 | |
40 | 943 int gftp_abort_transfer ( gftp_request * request ); |
944 | |
520 | 945 int gftp_stat_filename ( gftp_request * request, |
946 const char *filename, | |
787 | 947 mode_t * mode, |
948 off_t * filesize ); | |
500 | 949 |
1 | 950 void gftp_set_hostname ( gftp_request * request, |
951 const char *hostname ); | |
952 | |
953 void gftp_set_username ( gftp_request * request, | |
954 const char *username ); | |
955 | |
956 void gftp_set_password ( gftp_request * request, | |
957 const char *password ); | |
958 | |
959 void gftp_set_account ( gftp_request * request, | |
960 const char *account ); | |
961 | |
962 int gftp_set_directory ( gftp_request * request, | |
963 const char *directory ); | |
964 | |
965 void gftp_set_port ( gftp_request * request, | |
966 unsigned int port ); | |
967 | |
968 int gftp_remove_directory ( gftp_request * request, | |
969 const char *directory ); | |
970 | |
971 int gftp_remove_file ( gftp_request * request, | |
972 const char *file ); | |
973 | |
974 int gftp_make_directory ( gftp_request * request, | |
975 const char *directory ); | |
976 | |
977 int gftp_rename_file ( gftp_request * request, | |
978 const char *oldname, | |
979 const char *newname ); | |
980 | |
981 int gftp_chmod ( gftp_request * request, | |
982 const char *file, | |
499 | 983 mode_t mode ); |
1 | 984 |
985 int gftp_set_file_time ( gftp_request * request, | |
986 const char *file, | |
987 time_t datetime ); | |
988 | |
765 | 989 int gftp_site_cmd ( gftp_request * request, |
478 | 990 int specify_site, |
1 | 991 const char *command ); |
992 | |
58 | 993 off_t gftp_get_file_size ( gftp_request * request, |
1 | 994 const char *filename ); |
995 | |
996 void gftp_calc_kbs ( gftp_transfer * tdata, | |
997 ssize_t num_read ); | |
998 | |
102 | 999 time_t parse_time ( char *str, |
1000 char **endpos ); | |
1001 | |
91 | 1002 int gftp_parse_ls ( gftp_request * request, |
1003 const char *lsoutput, | |
485 | 1004 gftp_file *fle, |
1005 int fd ); | |
1 | 1006 |
1007 int gftp_get_all_subdirs ( gftp_transfer * transfer, | |
1008 void (*update_func) | |
1009 ( gftp_transfer * transfer )); | |
1010 | |
1011 int gftp_connect_server ( gftp_request * request, | |
122 | 1012 char *service, |
1013 char *proxy_hostname, | |
516 | 1014 unsigned int proxy_port ); |
1 | 1015 |
1016 struct hostent *r_gethostbyname ( const char *name, | |
1017 struct hostent *result_buf, | |
1018 int *h_errnop ); | |
1019 | |
1020 struct servent *r_getservbyname ( const char *name, | |
1021 const char *proto, | |
765 | 1022 /*@out@*/ struct servent *result_buf, |
1 | 1023 int *h_errnop ); |
122 | 1024 |
177 | 1025 int gftp_set_config_options ( gftp_request * request ); |
1 | 1026 |
1027 void print_file_list ( GList * list ); | |
1028 | |
201 | 1029 void gftp_free_getline_buffer ( gftp_getline_buffer ** rbuf ); |
168 | 1030 |
58 | 1031 ssize_t gftp_get_line ( gftp_request * request, |
765 | 1032 /*@out@*/ gftp_getline_buffer ** rbuf, |
1033 /*@out@*/ char * str, | |
41 | 1034 size_t len, |
58 | 1035 int fd ); |
1036 | |
168 | 1037 ssize_t gftp_fd_read ( gftp_request * request, |
58 | 1038 void *ptr, |
1039 size_t size, | |
1040 int fd ); | |
41 | 1041 |
168 | 1042 ssize_t gftp_fd_write ( gftp_request * request, |
58 | 1043 const char *ptr, |
41 | 1044 size_t size, |
58 | 1045 int fd ); |
1046 | |
1047 ssize_t gftp_writefmt ( gftp_request * request, | |
1048 int fd, | |
1049 const char *fmt, | |
1050 ... ); | |
1051 | |
168 | 1052 int gftp_fd_set_sockblocking ( gftp_request * request, |
58 | 1053 int fd, |
1054 int non_blocking ); | |
41 | 1055 |
63 | 1056 void gftp_swap_socks ( gftp_request * dest, |
1057 gftp_request * source ); | |
1058 | |
122 | 1059 void gftp_calc_kbs ( gftp_transfer * tdata, |
1060 ssize_t num_read ); | |
1061 | |
125 | 1062 int gftp_get_transfer_status ( gftp_transfer * tdata, |
1063 ssize_t num_read ); | |
1064 | |
182 | 1065 int gftp_fd_open ( gftp_request * request, |
1066 const char *pathname, | |
1067 int flags, | |
1068 mode_t perms ); | |
1069 | |
792 | 1070 void gftp_setup_startup_directory ( gftp_request * request, |
1071 const char *option_name ); | |
422 | 1072 |
542 | 1073 unsigned int gftp_protocol_default_port ( gftp_request * request ); |
1074 | |
146 | 1075 /* pty.c */ |
210 | 1076 char * gftp_get_pty_impl ( void ); |
179 | 1077 |
458 | 1078 pid_t gftp_exec ( gftp_request * request, |
1079 int *fdm, | |
1080 int *ptymfd, | |
210 | 1081 char **args ); |
146 | 1082 |
499 | 1083 char *gftp_convert_attributes_from_mode_t ( mode_t mode ); |
1084 | |
1085 mode_t gftp_convert_attributes_to_mode_t ( char *attribs ); | |
1086 | |
1087 | |
168 | 1088 #ifdef USE_SSL |
1089 /* sslcommon.c */ | |
1090 int gftp_ssl_startup ( gftp_request * request ); | |
1091 | |
1092 int gftp_ssl_session_setup ( gftp_request * request ); | |
1093 | |
1094 void gftp_ssl_free ( gftp_request * request ); | |
1095 | |
1096 ssize_t gftp_ssl_read ( gftp_request * request, | |
1097 void *ptr, | |
1098 size_t size, | |
1099 int fd ); | |
1100 | |
1101 ssize_t gftp_ssl_write ( gftp_request * request, | |
1102 const char *ptr, | |
1103 size_t size, | |
1104 int fd ); | |
1105 #endif /* USE_SSL */ | |
1106 | |
460 | 1107 /* UI dependent functions that must be implemented */ |
1108 int gftpui_protocol_ask_yes_no ( gftp_request * request, | |
1109 char *title, | |
1110 char *question ); | |
1111 | |
484 | 1112 char *gftpui_protocol_ask_user_input ( gftp_request * request, |
1113 char *title, | |
1114 char *question, | |
1115 int shown ); | |
1116 | |
469 | 1117 void gftpui_protocol_update_timeout ( gftp_request * request ); |
1118 | |
1 | 1119 #endif |
1120 |