Mercurial > gftp.yaz
annotate lib/gftp.h @ 950:c7d7a081cd9c
2008-03-04 Brian Masney <masneyb@gftp.org>
* lib/gftp.h lib/socket-connect.c lib/sockutils.c lib/protocols.c
lib/Makefile.am lib/charset-conv.c lib/parse-dir-listing.c - split
protocols.c into smaller files. No changes were made to the moved
functions.
author | masneyb |
---|---|
date | Tue, 04 Mar 2008 12:28:40 +0000 |
parents | 5b681cba67b2 |
children | a490d94a5b8e |
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 |
950 | 671 /* charset-conv.c */ |
672 /*@null@*/ char * gftp_string_to_utf8 ( gftp_request * request, | |
673 const char *str, | |
674 size_t *dest_len ); | |
675 | |
676 /*@null@*/ char * gftp_string_from_utf8 ( gftp_request * request, | |
677 int force_local, | |
678 const char *str, | |
679 size_t *dest_len ); | |
680 | |
681 /*@null@*/ char * gftp_filename_to_utf8 ( gftp_request * request, | |
682 const char *str, | |
683 size_t *dest_len ); | |
684 | |
685 /*@null@*/ char * gftp_filename_from_utf8 ( gftp_request * request, | |
686 const char *str, | |
687 size_t *dest_len ); | |
688 | |
1 | 689 /* config_file.c */ |
198 | 690 int gftp_config_parse_args ( char *str, |
691 int numargs, | |
692 int lineno, | |
765 | 693 /*@out@*/ char **first, |
198 | 694 ... ); |
695 | |
122 | 696 void gftp_add_bookmark ( gftp_bookmarks_var * newentry ); |
697 | |
124 | 698 void gftp_read_config_file ( char *global_data_path ); |
1 | 699 |
122 | 700 void gftp_write_bookmarks_file ( void ); |
1 | 701 |
702 void gftp_write_config_file ( void ); | |
703 | |
122 | 704 GHashTable * build_bookmarks_hash_table ( gftp_bookmarks_var * entry ); |
705 | |
706 void print_bookmarks ( gftp_bookmarks_var * bookmarks ); | |
707 | |
374 | 708 void gftp_lookup_global_option ( const char * key, |
765 | 709 /*@out@*/ void *value ); |
26 | 710 |
122 | 711 void gftp_lookup_request_option ( gftp_request * request, |
374 | 712 const char * key, |
765 | 713 /*@out@*/ void *value ); |
714 | |
1 | 715 |
229 | 716 void gftp_lookup_bookmark_option ( gftp_bookmarks_var * bm, |
374 | 717 const char * key, |
229 | 718 void *value ); |
719 | |
374 | 720 void gftp_set_global_option ( const char * key, |
227 | 721 const void *value ); |
122 | 722 |
723 void gftp_set_request_option ( gftp_request * request, | |
374 | 724 const char * key, |
229 | 725 const void *value ); |
726 | |
727 void gftp_set_bookmark_option ( gftp_bookmarks_var * bm, | |
374 | 728 const char * key, |
229 | 729 const void *value ); |
122 | 730 |
731 void gftp_register_config_vars ( gftp_config_vars *config_vars ); | |
1 | 732 |
201 | 733 void gftp_copy_local_options ( gftp_config_vars ** new_options_vars, |
734 GHashTable ** new_options_hash, | |
429 | 735 int *new_num_local_options_vars, |
201 | 736 gftp_config_vars * orig_options, |
737 int num_local_options_vars ); | |
738 | |
739 void gftp_config_free_options ( gftp_config_vars * options_vars, | |
740 GHashTable * options_hash, | |
741 int num_options_vars ); | |
742 | |
743 void gftp_bookmarks_destroy ( gftp_bookmarks_var * bookmarks ); | |
744 | |
218 | 745 void gftp_free_proxy_hosts ( GList * proxy_hosts ); |
746 | |
747 GList * gftp_copy_proxy_hosts ( GList * proxy_hosts ); | |
748 | |
1 | 749 /* misc.c */ |
765 | 750 /*@null@*/ char *insert_commas ( off_t number, |
1 | 751 char *dest_str, |
752 size_t dest_len ); | |
753 | |
754 char *alltrim ( char *str ); | |
755 | |
555 | 756 char *gftp_expand_path ( gftp_request * request, |
757 const char *src ); | |
1 | 758 |
759 void make_nonnull ( char **str ); | |
760 | |
821 | 761 int gftp_match_filespec ( gftp_request * request, |
762 const char *filename, | |
374 | 763 const char *filespec ); |
1 | 764 |
765 int gftp_parse_command_line ( int *argc, | |
766 char ***argv ); | |
767 | |
768 void gftp_usage ( void ); | |
769 | |
770 gint string_hash_compare ( gconstpointer path1, | |
771 gconstpointer path2 ); | |
772 | |
773 guint string_hash_function ( gconstpointer key ); | |
774 | |
852 | 775 gint uint_hash_compare ( gconstpointer path1, |
776 gconstpointer path2 ); | |
777 | |
778 guint uint_hash_function ( gconstpointer key ); | |
779 | |
1 | 780 void free_file_list ( GList * filelist ); |
781 | |
782 gftp_file * copy_fdata ( gftp_file * fle ); | |
783 | |
784 int compare_request ( gftp_request * request1, | |
785 gftp_request * request2, | |
786 int compare_dirs ); | |
787 | |
129 | 788 gftp_transfer * gftp_tdata_new ( void ); |
789 | |
1 | 790 void free_tdata ( gftp_transfer * tdata ); |
791 | |
368 | 792 gftp_request * gftp_copy_request ( gftp_request * req ); |
1 | 793 |
16 | 794 GList * gftp_sort_filelist ( GList * filelist, |
795 int column, | |
796 int asds ); | |
797 | |
830 | 798 char * gftp_gen_ls_string ( gftp_request * request, |
799 gftp_file * fle, | |
131 | 800 char *file_prefixstr, |
801 char *file_suffixstr ); | |
802 | |
168 | 803 char * base64_encode ( char *str ); |
804 | |
609 | 805 void gftp_free_bookmark ( gftp_bookmarks_var * entry, |
806 int free_node ); | |
199 | 807 |
201 | 808 void gftp_shutdown ( void ); |
199 | 809 |
207 | 810 GList * get_next_selection ( GList * selection, |
811 GList ** list, | |
812 int *curnum ); | |
813 | |
555 | 814 char * gftp_build_path ( gftp_request * request, |
815 const char *first_element, | |
227 | 816 ... ); |
817 | |
290 | 818 void gftp_locale_init ( void ); |
819 | |
330 | 820 char * gftp_scramble_password ( const char *password ); |
821 | |
822 char * gftp_descramble_password ( const char *password ); | |
823 | |
378 | 824 int gftp_get_transfer_action ( gftp_request * request, |
825 gftp_file * fle ); | |
826 | |
483 | 827 char * gftp_get_share_dir ( void ); |
828 | |
402 | 829 /* mkstemps.c */ |
830 int mkstemps ( char *template, | |
831 int suffix_len ); | |
832 | |
950 | 833 /* parse-dir-listing.c */ |
834 time_t parse_time ( char *str, | |
835 char **endpos ); | |
836 | |
837 int gftp_parse_ls ( gftp_request * request, | |
838 const char *lsoutput, | |
839 gftp_file *fle, | |
840 int fd ); | |
841 | |
1 | 842 /* protocols.c */ |
843 #define GFTP_FTP_NUM 0 | |
389 | 844 #define GFTP_FTPS_NUM 1 |
845 #define GFTP_HTTP_NUM 2 | |
846 #define GFTP_HTTPS_NUM 3 | |
847 #define GFTP_LOCAL_NUM 4 | |
848 #define GFTP_SSHV2_NUM 5 | |
849 #define GFTP_BOOKMARK_NUM 6 | |
661 | 850 #define GFTP_FSP_NUM 7 |
122 | 851 |
1 | 852 #define GFTP_IS_CONNECTED(request) ((request) != NULL && \ |
169 | 853 ((request)->datafd > 0 || \ |
58 | 854 (request)->cached || \ |
855 (request)->always_connected)) | |
1 | 856 |
857 | |
173 | 858 int rfc959_init ( gftp_request * request ); |
1 | 859 |
122 | 860 void rfc959_register_module ( void ); |
861 | |
1 | 862 int rfc959_get_next_file ( gftp_request * request, |
863 gftp_file *fle, | |
58 | 864 int fd ); |
1 | 865 |
451 | 866 int rfc959_connect ( gftp_request * request ); |
867 | |
389 | 868 int ftps_init ( gftp_request * request ); |
869 | |
870 void ftps_register_module ( void ); | |
871 | |
173 | 872 int rfc2068_init ( gftp_request * request ); |
1 | 873 |
122 | 874 void rfc2068_register_module ( void ); |
875 | |
173 | 876 int https_init ( gftp_request * request ); |
168 | 877 |
878 void https_register_module ( void ); | |
879 | |
173 | 880 int local_init ( gftp_request * request ); |
1 | 881 |
122 | 882 void local_register_module ( void ); |
883 | |
173 | 884 int sshv2_init ( gftp_request * request ); |
1 | 885 |
122 | 886 void sshv2_register_module ( void ); |
887 | |
174 | 888 void ssl_register_module ( void ); |
889 | |
173 | 890 int bookmark_init ( gftp_request * request ); |
1 | 891 |
122 | 892 void bookmark_register_module ( void ); |
893 | |
661 | 894 int fsp_init ( gftp_request * request ); |
895 | |
896 void fsp_register_module ( void ); | |
897 | |
1 | 898 gftp_request *gftp_request_new ( void ); |
899 | |
67 | 900 void gftp_request_destroy ( gftp_request * request, |
901 int free_request ); | |
1 | 902 |
309 | 903 void gftp_copy_param_options ( gftp_request * dest_request, |
904 gftp_request * src_request ); | |
905 | |
598 | 906 void gftp_file_destroy ( gftp_file *file, |
907 int free_it ); | |
1 | 908 |
909 int gftp_connect ( gftp_request * request ); | |
910 | |
911 void gftp_disconnect ( gftp_request * request ); | |
912 | |
58 | 913 off_t gftp_get_file ( gftp_request * request, |
1 | 914 const char *filename, |
244 | 915 off_t startsize ); |
1 | 916 |
917 int gftp_put_file ( gftp_request * request, | |
918 const char *filename, | |
244 | 919 off_t startsize, |
920 off_t totalsize ); | |
1 | 921 |
261 | 922 off_t gftp_transfer_file ( gftp_request *fromreq, |
1 | 923 const char *fromfile, |
244 | 924 off_t fromsize, |
1 | 925 gftp_request *toreq, |
926 const char *tofile, | |
244 | 927 off_t tosize ); |
1 | 928 |
58 | 929 ssize_t gftp_get_next_file_chunk ( gftp_request * request, |
1 | 930 char *buf, |
931 size_t size ); | |
932 | |
58 | 933 ssize_t gftp_put_next_file_chunk ( gftp_request * request, |
1 | 934 char *buf, |
935 size_t size ); | |
936 | |
937 int gftp_list_files ( gftp_request * request ); | |
938 | |
87 | 939 int gftp_parse_bookmark ( gftp_request * request, |
243 | 940 gftp_request * local_request, |
275 | 941 const char * bookmark, |
942 int *refresh_local ); | |
87 | 943 |
1 | 944 int gftp_parse_url ( gftp_request * request, |
945 const char *url ); | |
946 | |
947 int gftp_get_next_file ( gftp_request * request, | |
377 | 948 const char *filespec, |
1 | 949 gftp_file *fle ); |
950 | |
951 int gftp_end_transfer ( gftp_request * request ); | |
952 | |
40 | 953 int gftp_abort_transfer ( gftp_request * request ); |
954 | |
520 | 955 int gftp_stat_filename ( gftp_request * request, |
956 const char *filename, | |
787 | 957 mode_t * mode, |
958 off_t * filesize ); | |
500 | 959 |
1 | 960 void gftp_set_hostname ( gftp_request * request, |
961 const char *hostname ); | |
962 | |
963 void gftp_set_username ( gftp_request * request, | |
964 const char *username ); | |
965 | |
966 void gftp_set_password ( gftp_request * request, | |
967 const char *password ); | |
968 | |
969 void gftp_set_account ( gftp_request * request, | |
970 const char *account ); | |
971 | |
972 int gftp_set_directory ( gftp_request * request, | |
973 const char *directory ); | |
974 | |
975 void gftp_set_port ( gftp_request * request, | |
976 unsigned int port ); | |
977 | |
978 int gftp_remove_directory ( gftp_request * request, | |
979 const char *directory ); | |
980 | |
981 int gftp_remove_file ( gftp_request * request, | |
982 const char *file ); | |
983 | |
984 int gftp_make_directory ( gftp_request * request, | |
985 const char *directory ); | |
986 | |
987 int gftp_rename_file ( gftp_request * request, | |
988 const char *oldname, | |
989 const char *newname ); | |
990 | |
991 int gftp_chmod ( gftp_request * request, | |
992 const char *file, | |
499 | 993 mode_t mode ); |
1 | 994 |
995 int gftp_set_file_time ( gftp_request * request, | |
996 const char *file, | |
997 time_t datetime ); | |
998 | |
765 | 999 int gftp_site_cmd ( gftp_request * request, |
478 | 1000 int specify_site, |
1 | 1001 const char *command ); |
1002 | |
58 | 1003 off_t gftp_get_file_size ( gftp_request * request, |
1 | 1004 const char *filename ); |
1005 | |
1006 void gftp_calc_kbs ( gftp_transfer * tdata, | |
1007 ssize_t num_read ); | |
1008 | |
1009 int gftp_get_all_subdirs ( gftp_transfer * transfer, | |
1010 void (*update_func) | |
1011 ( gftp_transfer * transfer )); | |
1012 | |
1013 struct hostent *r_gethostbyname ( const char *name, | |
1014 struct hostent *result_buf, | |
1015 int *h_errnop ); | |
1016 | |
1017 struct servent *r_getservbyname ( const char *name, | |
1018 const char *proto, | |
765 | 1019 /*@out@*/ struct servent *result_buf, |
1 | 1020 int *h_errnop ); |
122 | 1021 |
177 | 1022 int gftp_set_config_options ( gftp_request * request ); |
1 | 1023 |
1024 void print_file_list ( GList * list ); | |
1025 | |
63 | 1026 void gftp_swap_socks ( gftp_request * dest, |
1027 gftp_request * source ); | |
1028 | |
122 | 1029 void gftp_calc_kbs ( gftp_transfer * tdata, |
1030 ssize_t num_read ); | |
1031 | |
125 | 1032 int gftp_get_transfer_status ( gftp_transfer * tdata, |
1033 ssize_t num_read ); | |
1034 | |
182 | 1035 int gftp_fd_open ( gftp_request * request, |
1036 const char *pathname, | |
1037 int flags, | |
1038 mode_t perms ); | |
1039 | |
792 | 1040 void gftp_setup_startup_directory ( gftp_request * request, |
1041 const char *option_name ); | |
422 | 1042 |
542 | 1043 unsigned int gftp_protocol_default_port ( gftp_request * request ); |
1044 | |
146 | 1045 /* pty.c */ |
210 | 1046 char * gftp_get_pty_impl ( void ); |
179 | 1047 |
458 | 1048 pid_t gftp_exec ( gftp_request * request, |
1049 int *fdm, | |
1050 int *ptymfd, | |
210 | 1051 char **args ); |
146 | 1052 |
499 | 1053 char *gftp_convert_attributes_from_mode_t ( mode_t mode ); |
1054 | |
1055 mode_t gftp_convert_attributes_to_mode_t ( char *attribs ); | |
1056 | |
1057 | |
168 | 1058 #ifdef USE_SSL |
1059 /* sslcommon.c */ | |
1060 int gftp_ssl_startup ( gftp_request * request ); | |
1061 | |
1062 int gftp_ssl_session_setup ( gftp_request * request ); | |
1063 | |
1064 void gftp_ssl_free ( gftp_request * request ); | |
1065 | |
1066 ssize_t gftp_ssl_read ( gftp_request * request, | |
1067 void *ptr, | |
1068 size_t size, | |
1069 int fd ); | |
1070 | |
1071 ssize_t gftp_ssl_write ( gftp_request * request, | |
1072 const char *ptr, | |
1073 size_t size, | |
1074 int fd ); | |
1075 #endif /* USE_SSL */ | |
1076 | |
460 | 1077 /* UI dependent functions that must be implemented */ |
1078 int gftpui_protocol_ask_yes_no ( gftp_request * request, | |
1079 char *title, | |
1080 char *question ); | |
1081 | |
484 | 1082 char *gftpui_protocol_ask_user_input ( gftp_request * request, |
1083 char *title, | |
1084 char *question, | |
1085 int shown ); | |
1086 | |
469 | 1087 void gftpui_protocol_update_timeout ( gftp_request * request ); |
1088 | |
1 | 1089 #endif |
1090 | |
950 | 1091 /* socket-connect.c */ |
1092 int gftp_connect_server ( gftp_request * request, | |
1093 char *service, | |
1094 char *proxy_hostname, | |
1095 unsigned int proxy_port ); | |
1096 | |
1097 /* sockutils.c */ | |
1098 ssize_t gftp_get_line ( gftp_request * request, | |
1099 /*@out@*/ gftp_getline_buffer ** rbuf, | |
1100 /*@out@*/ char * str, | |
1101 size_t len, | |
1102 int fd ); | |
1103 | |
1104 void gftp_free_getline_buffer ( gftp_getline_buffer ** rbuf ); | |
1105 | |
1106 ssize_t gftp_fd_read ( gftp_request * request, | |
1107 void *ptr, | |
1108 size_t size, | |
1109 int fd ); | |
1110 | |
1111 ssize_t gftp_fd_write ( gftp_request * request, | |
1112 const char *ptr, | |
1113 size_t size, | |
1114 int fd ); | |
1115 | |
1116 ssize_t gftp_writefmt ( gftp_request * request, | |
1117 int fd, | |
1118 const char *fmt, | |
1119 ... ); | |
1120 | |
1121 int gftp_fd_set_sockblocking ( gftp_request * request, | |
1122 int fd, | |
1123 int non_blocking ); | |
1124 |