annotate lib/rfc959.c @ 341:eedc2c5727fa

2003-12-28 Brian Masney <masneyb@gftp.org> **** NOTE: this commit breaks a lot of functionality in gftp. I **** **** still have more work to do on this. Please don't email me **** **** saying that the CVS code is broken. **** * lib/bookmark.c lib/gftp.h lib/local.c lib/options.h lib/rfc2068.c lib/rfc959.c lib/sshv2.c - moved the use_threads option from the request structure over to the protocol declaration in options.h. * lib/options.h src/gtk/gftp-gtk.c - added cmd_in_gui option. When this option is enabled, a new toolbar will be shown in the GTK+ port that will allow you to control the GUI by entering manual commands. * src/Makefile.am - added uicommon directory * src/gtk/Makefile.am src/text/Makefile.am - link in the uicommon library. * src/uicommon/* src/text/gftp-text.c - moved most of the functionality of the text port over to the uicommon directory. Made this code a little more generic so that the GTK+ port can have a text interface associated with it. * src/gtk/gtkui.c src/gtk/gftp-gtk.c src/gtk/mkdir_dialog.c src/gtk/rename_dialog.c src/gtk/menu-items.c src/gtk/misc-gtk.c - started to clean up the callback functions and make them more tightly integrated with the uicommon code. * src/gtk/bookmarks.c src/gtk/chmod_dialog.c src/gtk/delete_dialog.c src/gtk/gftp-gtk.c src/gtk/menu-items.c src/gtk/misc-gtk.c src/gtk/transfer.c - s/refresh/gftpui_refresh/g s/jmp_environment/gftpui_common_jmp_environment/g s/request->use_threads/gftpui_common_use_threads (request)/g * src/gtk/options_dialog.c (apply_changes) - whenever the options are saved, check to see if the command entry needs to be shown or hidden.
author masneyb
date Sun, 28 Dec 2003 16:02:07 +0000
parents 542a3e8708f9
children 28a50fb598ed
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1 /*****************************************************************************/
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
2 /* rfc959.c - General purpose routines for the FTP protocol (RFC 959) */
122
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 114
diff changeset
3 /* Copyright (C) 1998-2003 Brian Masney <masneyb@gftp.org> */
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
4 /* */
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
5 /* This program is free software; you can redistribute it and/or modify */
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
6 /* it under the terms of the GNU General Public License as published by */
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
7 /* the Free Software Foundation; either version 2 of the License, or */
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
8 /* (at your option) any later version. */
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
9 /* */
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
10 /* This program is distributed in the hope that it will be useful, */
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
11 /* but WITHOUT ANY WARRANTY; without even the implied warranty of */
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
12 /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
13 /* GNU General Public License for more details. */
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
14 /* */
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
15 /* You should have received a copy of the GNU General Public License */
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
16 /* along with this program; if not, write to the Free Software */
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
17 /* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111 USA */
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
18 /*****************************************************************************/
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
19
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
20 #include "gftp.h"
33
c8ec7877432e 2002-10-06 Brian Masney <masneyb@gftp.org>
masneyb
parents: 15
diff changeset
21 static const char cvsid[] = "$Id$";
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
22
126
1e65871fdfa1 2003-4-9 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
23 static gftp_textcomboedt_data gftp_proxy_type[] = {
136
84b3e69807a2 2003-4-18 Brian Masney <masneyb@gftp.org>
masneyb
parents: 126
diff changeset
24 {N_("none"), "", 0},
84b3e69807a2 2003-4-18 Brian Masney <masneyb@gftp.org>
masneyb
parents: 126
diff changeset
25 {N_("SITE command"), "USER %pu\nPASS %pp\nSITE %hh\nUSER %hu\nPASS %hp\n", 0},
84b3e69807a2 2003-4-18 Brian Masney <masneyb@gftp.org>
masneyb
parents: 126
diff changeset
26 {N_("user@host"), "USER %pu\nPASS %pp\nUSER %hu@%hh\nPASS %hp\n", 0},
84b3e69807a2 2003-4-18 Brian Masney <masneyb@gftp.org>
masneyb
parents: 126
diff changeset
27 {N_("user@host:port"), "USER %hu@%hh:%ho\nPASS %hp\n", 0},
84b3e69807a2 2003-4-18 Brian Masney <masneyb@gftp.org>
masneyb
parents: 126
diff changeset
28 {N_("AUTHENTICATE"), "USER %hu@%hh\nPASS %hp\nSITE AUTHENTICATE %pu\nSITE RESPONSE %pp\n", 0},
84b3e69807a2 2003-4-18 Brian Masney <masneyb@gftp.org>
masneyb
parents: 126
diff changeset
29 {N_("user@host port"), "USER %hu@%hh %ho\nPASS %hp\n", 0},
84b3e69807a2 2003-4-18 Brian Masney <masneyb@gftp.org>
masneyb
parents: 126
diff changeset
30 {N_("user@host NOAUTH"), "USER %hu@%hh\nPASS %hp\n", 0},
84b3e69807a2 2003-4-18 Brian Masney <masneyb@gftp.org>
masneyb
parents: 126
diff changeset
31 {N_("HTTP Proxy"), "http", 0},
84b3e69807a2 2003-4-18 Brian Masney <masneyb@gftp.org>
masneyb
parents: 126
diff changeset
32 {N_("Custom"), "", GFTP_TEXTCOMBOEDT_EDITABLE},
126
1e65871fdfa1 2003-4-9 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
33 {NULL, NULL}
1e65871fdfa1 2003-4-9 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
34 };
1e65871fdfa1 2003-4-9 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
35
122
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 114
diff changeset
36 static gftp_config_vars config_vars[] =
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 114
diff changeset
37 {
227
a85a097bbb02 2003-7-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 201
diff changeset
38 {"", N_("FTP"), gftp_option_type_notebook, NULL, NULL,
a85a097bbb02 2003-7-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 201
diff changeset
39 GFTP_CVARS_FLAGS_SHOW_BOOKMARK, NULL, GFTP_PORT_GTK, NULL},
122
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 114
diff changeset
40
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 114
diff changeset
41 {"email", N_("Email address:"),
227
a85a097bbb02 2003-7-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 201
diff changeset
42 gftp_option_type_text, "", NULL, GFTP_CVARS_FLAGS_SHOW_BOOKMARK,
122
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 114
diff changeset
43 N_("This is the password that will be used whenever you log into a remote FTP server as anonymous"),
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 114
diff changeset
44 GFTP_PORT_ALL, NULL},
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 114
diff changeset
45 {"ftp_proxy_host", N_("Proxy hostname:"),
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 114
diff changeset
46 gftp_option_type_text, "", NULL, 0,
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 114
diff changeset
47 N_("Firewall hostname"), GFTP_PORT_ALL, NULL},
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 114
diff changeset
48 {"ftp_proxy_port", N_("Proxy port:"),
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 114
diff changeset
49 gftp_option_type_int, GINT_TO_POINTER(21), NULL, 0,
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 114
diff changeset
50 N_("Port to connect to on the firewall"), GFTP_PORT_ALL, NULL},
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 114
diff changeset
51 {"ftp_proxy_username", N_("Proxy username:"),
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 114
diff changeset
52 gftp_option_type_text, "", NULL, 0,
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 114
diff changeset
53 N_("Your firewall username"), GFTP_PORT_ALL, NULL},
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 114
diff changeset
54 {"ftp_proxy_password", N_("Proxy password:"),
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 114
diff changeset
55 gftp_option_type_hidetext, "", NULL, 0,
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 114
diff changeset
56 N_("Your firewall password"), GFTP_PORT_ALL, NULL},
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 114
diff changeset
57 {"ftp_proxy_account", N_("Proxy account:"),
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 114
diff changeset
58 gftp_option_type_text, "", NULL, 0,
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 114
diff changeset
59 N_("Your firewall account (optional)"), GFTP_PORT_ALL, NULL},
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 114
diff changeset
60
126
1e65871fdfa1 2003-4-9 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
61 {"proxy_config", N_("Proxy server type:"),
1e65871fdfa1 2003-4-9 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
62 gftp_option_type_textcomboedt, "", gftp_proxy_type, 0,
149
dfc22cead576 2003-04-27 Christian Rose <menthos@menthos.com>
menthos
parents: 146
diff changeset
63 /* xgettext:no-c-format */
126
1e65871fdfa1 2003-4-9 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
64 N_("This specifies how your proxy server expects us to log in. You can specify a 2 character replacement string prefixed by a % that will be replaced with the proper data. The first character can be either p for proxy or h for the host of the FTP server. The second character can be u (user), p (pass), h (host), o (port) or a (account). For example, to specify the proxy user, you can you type in %pu"),
1e65871fdfa1 2003-4-9 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
65 GFTP_PORT_ALL, NULL},
1e65871fdfa1 2003-4-9 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
66
136
84b3e69807a2 2003-4-18 Brian Masney <masneyb@gftp.org>
masneyb
parents: 126
diff changeset
67 {"passive_transfer", N_("Passive file transfers"),
227
a85a097bbb02 2003-7-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 201
diff changeset
68 gftp_option_type_checkbox, GINT_TO_POINTER(1), NULL,
a85a097bbb02 2003-7-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 201
diff changeset
69 GFTP_CVARS_FLAGS_SHOW_BOOKMARK,
136
84b3e69807a2 2003-4-18 Brian Masney <masneyb@gftp.org>
masneyb
parents: 126
diff changeset
70 N_("If this is enabled, then the remote FTP server will open up a port for the data connection. If you are behind a firewall, you will need to enable this. Generally, it is a good idea to keep this enabled unless you are connecting to an older FTP server that doesn't support this. If this is disabled, then gFTP will open up a port on the client side and the remote server will attempt to connect to it."),
84b3e69807a2 2003-4-18 Brian Masney <masneyb@gftp.org>
masneyb
parents: 126
diff changeset
71 GFTP_PORT_ALL, NULL},
84b3e69807a2 2003-4-18 Brian Masney <masneyb@gftp.org>
masneyb
parents: 126
diff changeset
72 {"resolve_symlinks", N_("Resolve Remote Symlinks (LIST -L)"),
227
a85a097bbb02 2003-7-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 201
diff changeset
73 gftp_option_type_checkbox, GINT_TO_POINTER(1), NULL,
a85a097bbb02 2003-7-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 201
diff changeset
74 GFTP_CVARS_FLAGS_SHOW_BOOKMARK,
136
84b3e69807a2 2003-4-18 Brian Masney <masneyb@gftp.org>
masneyb
parents: 126
diff changeset
75 N_("The remote FTP server will attempt to resolve symlinks in the directory listings. Generally, this is a good idea to leave enabled. The only time you will want to disable this is if the remote FTP server doesn't support the -L option to LIST"),
84b3e69807a2 2003-4-18 Brian Masney <masneyb@gftp.org>
masneyb
parents: 126
diff changeset
76 GFTP_PORT_ALL, NULL},
84b3e69807a2 2003-4-18 Brian Masney <masneyb@gftp.org>
masneyb
parents: 126
diff changeset
77 {"ascii_transfers", N_("Transfer files in ASCII mode"),
227
a85a097bbb02 2003-7-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 201
diff changeset
78 gftp_option_type_checkbox, GINT_TO_POINTER(0), NULL,
a85a097bbb02 2003-7-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 201
diff changeset
79 GFTP_CVARS_FLAGS_SHOW_BOOKMARK,
136
84b3e69807a2 2003-4-18 Brian Masney <masneyb@gftp.org>
masneyb
parents: 126
diff changeset
80 N_("If you are transfering a text file from Windows to UNIX box or vice versa, then you should enable this. Each system represents newlines differently for text files. If you are transfering from UNIX to UNIX, then it is safe to leave this off. If you are downloading binary data, you will want to disable this."),
84b3e69807a2 2003-4-18 Brian Masney <masneyb@gftp.org>
masneyb
parents: 126
diff changeset
81 GFTP_PORT_ALL, NULL},
84b3e69807a2 2003-4-18 Brian Masney <masneyb@gftp.org>
masneyb
parents: 126
diff changeset
82
122
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 114
diff changeset
83 {NULL, NULL, 0, NULL, NULL, 0, NULL, 0, NULL}
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 114
diff changeset
84 };
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 114
diff changeset
85
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 114
diff changeset
86
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 48
diff changeset
87 typedef struct rfc959_params_tag
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 48
diff changeset
88 {
169
d40f9db52cdf 2003-6-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 168
diff changeset
89 gftp_getline_buffer * datafd_rbuf,
d40f9db52cdf 2003-6-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 168
diff changeset
90 * dataconn_rbuf;
d40f9db52cdf 2003-6-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 168
diff changeset
91 int data_connection;
292
e5ce6f15290f 2003-10-19 Brian Masney <masneyb@gftp.org>
masneyb
parents: 288
diff changeset
92 unsigned int is_ascii_transfer : 1,
e5ce6f15290f 2003-10-19 Brian Masney <masneyb@gftp.org>
masneyb
parents: 288
diff changeset
93 sent_retr : 1;
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 48
diff changeset
94 } rfc959_parms;
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 48
diff changeset
95
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 48
diff changeset
96
48
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
97 static int
292
e5ce6f15290f 2003-10-19 Brian Masney <masneyb@gftp.org>
masneyb
parents: 288
diff changeset
98 rfc959_read_response (gftp_request * request, int disconnect_on_42x)
48
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
99 {
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
100 char tempstr[255], code[4];
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 48
diff changeset
101 rfc959_parms * parms;
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 48
diff changeset
102 ssize_t num_read;
48
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
103
84
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
104 g_return_val_if_fail (request != NULL, GFTP_EFATAL);
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
105 g_return_val_if_fail (request->protonum == GFTP_FTP_NUM, GFTP_EFATAL);
169
d40f9db52cdf 2003-6-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 168
diff changeset
106 g_return_val_if_fail (request->datafd > 0, GFTP_EFATAL);
48
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
107
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
108 *code = '\0';
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
109 if (request->last_ftp_response)
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
110 {
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
111 g_free (request->last_ftp_response);
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
112 request->last_ftp_response = NULL;
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
113 }
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
114
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 48
diff changeset
115 parms = request->protocol_data;
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 48
diff changeset
116
48
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
117 do
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
118 {
169
d40f9db52cdf 2003-6-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 168
diff changeset
119 if ((num_read = gftp_get_line (request, &parms->datafd_rbuf, tempstr,
d40f9db52cdf 2003-6-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 168
diff changeset
120 sizeof (tempstr), request->datafd)) <= 0)
48
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
121 break;
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 48
diff changeset
122
48
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
123 if (isdigit ((int) *tempstr) && isdigit ((int) *(tempstr + 1))
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
124 && isdigit ((int) *(tempstr + 2)))
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
125 {
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
126 strncpy (code, tempstr, 3);
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
127 code[3] = ' ';
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
128 }
186
13ca1defdc75 2003-6-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 182
diff changeset
129 request->logging_function (gftp_logging_recv, request,
48
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
130 "%s\n", tempstr);
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
131 }
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
132 while (strncmp (code, tempstr, 4) != 0);
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
133
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 48
diff changeset
134 if (num_read < 0)
84
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
135 return ((int) num_read);
48
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
136
105
ae13b18c9336 2003-2-9 Brian Masney <masneyb@gftp.org>
masneyb
parents: 91
diff changeset
137 request->last_ftp_response = g_strdup (tempstr);
48
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
138
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
139 if (request->last_ftp_response[0] == '4' &&
292
e5ce6f15290f 2003-10-19 Brian Masney <masneyb@gftp.org>
masneyb
parents: 288
diff changeset
140 request->last_ftp_response[1] == '2' &&
e5ce6f15290f 2003-10-19 Brian Masney <masneyb@gftp.org>
masneyb
parents: 288
diff changeset
141 disconnect_on_42x)
48
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
142 gftp_disconnect (request);
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
143
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
144 return (*request->last_ftp_response);
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
145 }
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
146
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
147
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
148 static int
292
e5ce6f15290f 2003-10-19 Brian Masney <masneyb@gftp.org>
masneyb
parents: 288
diff changeset
149 rfc959_send_command (gftp_request * request, const char *command,
e5ce6f15290f 2003-10-19 Brian Masney <masneyb@gftp.org>
masneyb
parents: 288
diff changeset
150 int read_response)
48
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
151 {
84
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
152 int ret;
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
153
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
154 g_return_val_if_fail (request != NULL, GFTP_EFATAL);
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
155 g_return_val_if_fail (request->protonum == GFTP_FTP_NUM, GFTP_EFATAL);
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
156 g_return_val_if_fail (command != NULL, GFTP_EFATAL);
169
d40f9db52cdf 2003-6-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 168
diff changeset
157 g_return_val_if_fail (request->datafd > 0, GFTP_EFATAL);
48
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
158
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
159 if (strncmp (command, "PASS", 4) == 0)
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
160 {
186
13ca1defdc75 2003-6-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 182
diff changeset
161 request->logging_function (gftp_logging_send, request,
48
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
162 "PASS xxxx\n");
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
163 }
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
164 else if (strncmp (command, "ACCT", 4) == 0)
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
165 {
186
13ca1defdc75 2003-6-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 182
diff changeset
166 request->logging_function (gftp_logging_send, request,
48
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
167 "ACCT xxxx\n");
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
168 }
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
169 else
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
170 {
186
13ca1defdc75 2003-6-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 182
diff changeset
171 request->logging_function (gftp_logging_send, request, "%s",
48
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
172 command);
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
173 }
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
174
168
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 151
diff changeset
175 if ((ret = gftp_fd_write (request, command, strlen (command),
169
d40f9db52cdf 2003-6-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 168
diff changeset
176 request->datafd)) < 0)
84
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
177 return (ret);
48
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
178
292
e5ce6f15290f 2003-10-19 Brian Masney <masneyb@gftp.org>
masneyb
parents: 288
diff changeset
179 if (read_response)
e5ce6f15290f 2003-10-19 Brian Masney <masneyb@gftp.org>
masneyb
parents: 288
diff changeset
180 return (rfc959_read_response (request, 1));
e5ce6f15290f 2003-10-19 Brian Masney <masneyb@gftp.org>
masneyb
parents: 288
diff changeset
181 else
e5ce6f15290f 2003-10-19 Brian Masney <masneyb@gftp.org>
masneyb
parents: 288
diff changeset
182 return (0);
48
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
183 }
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
184
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
185
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
186 static char *
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
187 parse_ftp_proxy_string (gftp_request * request)
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
188 {
298
6e0b9ca541e2 2003-10-26 Brian Masney <masneyb@gftp.org>
masneyb
parents: 292
diff changeset
189 char *startpos, *endpos, *newstr, *newval, tempport[6], *proxy_config, *utf8,
126
1e65871fdfa1 2003-4-9 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
190 savechar;
1e65871fdfa1 2003-4-9 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
191 size_t len;
325
0fcc6468a0af 2003-12-4 Brian Masney <masneyb@gftp.org>
masneyb
parents: 319
diff changeset
192 intptr_t tmp;
48
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
193
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
194 g_return_val_if_fail (request != NULL, NULL);
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
195 g_return_val_if_fail (request->protonum == GFTP_FTP_NUM, NULL);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
196
122
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 114
diff changeset
197 gftp_lookup_request_option (request, "proxy_config", &proxy_config);
126
1e65871fdfa1 2003-4-9 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
198
1e65871fdfa1 2003-4-9 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
199 newstr = g_malloc0 (1);
1e65871fdfa1 2003-4-9 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
200 len = 0;
122
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 114
diff changeset
201 startpos = endpos = proxy_config;
48
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
202 while (*endpos != '\0')
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
203 {
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
204 if (*endpos == '%' && tolower ((int) *(endpos + 1)) == 'p')
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
205 {
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
206 switch (tolower ((int) *(endpos + 2)))
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
207 {
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
208 case 'u':
124
65048c959029 2003-4-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 122
diff changeset
209 gftp_lookup_request_option (request, "ftp_proxy_username", &newval);
48
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
210 break;
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
211 case 'p':
124
65048c959029 2003-4-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 122
diff changeset
212 gftp_lookup_request_option (request, "ftp_proxy_password", &newval);
48
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
213 break;
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
214 case 'h':
124
65048c959029 2003-4-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 122
diff changeset
215 gftp_lookup_request_option (request, "ftp_proxy_host", &newval);
48
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
216 break;
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
217 case 'o':
124
65048c959029 2003-4-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 122
diff changeset
218 gftp_lookup_request_option (request, "ftp_proxy_port", &tmp);
325
0fcc6468a0af 2003-12-4 Brian Masney <masneyb@gftp.org>
masneyb
parents: 319
diff changeset
219 g_snprintf (tempport, sizeof (tempport), "%d", (int)tmp);
48
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
220 newval = tempport;
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
221 break;
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
222 case 'a':
124
65048c959029 2003-4-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 122
diff changeset
223 gftp_lookup_request_option (request, "ftp_proxy_account", &newval);
48
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
224 break;
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
225 default:
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
226 endpos++;
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
227 continue;
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
228 }
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
229 }
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
230 else if (*endpos == '%' && tolower ((int) *(endpos + 1)) == 'h')
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
231 {
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
232 switch (tolower ((int) *(endpos + 2)))
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
233 {
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
234 case 'u':
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
235 newval = request->username;
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
236 break;
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
237 case 'p':
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
238 newval = request->password;
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
239 break;
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
240 case 'h':
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
241 newval = request->hostname;
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
242 break;
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
243 case 'o':
126
1e65871fdfa1 2003-4-9 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
244 g_snprintf (tempport, sizeof (tempport), "%d", request->port);
48
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
245 newval = tempport;
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
246 break;
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
247 case 'a':
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
248 newval = request->account;
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
249 break;
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
250 default:
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
251 endpos++;
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
252 continue;
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
253 }
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
254 }
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
255 else if (*endpos == '%' && tolower ((int) *(endpos + 1)) == 'n')
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
256 {
126
1e65871fdfa1 2003-4-9 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
257 savechar = *endpos;
1e65871fdfa1 2003-4-9 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
258 *endpos = '\0';
1e65871fdfa1 2003-4-9 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
259
1e65871fdfa1 2003-4-9 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
260 len += strlen (startpos) + 2;
1e65871fdfa1 2003-4-9 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
261 newstr = g_realloc (newstr, sizeof (char) * (len + 1));
1e65871fdfa1 2003-4-9 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
262 strcat (newstr, startpos);
1e65871fdfa1 2003-4-9 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
263 strcat (newstr, "\r\n");
1e65871fdfa1 2003-4-9 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
264
1e65871fdfa1 2003-4-9 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
265 *endpos = savechar;
48
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
266 endpos += 2;
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
267 startpos = endpos;
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
268 continue;
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
269 }
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
270 else
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
271 {
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
272 endpos++;
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
273 continue;
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
274 }
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
275
126
1e65871fdfa1 2003-4-9 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
276 savechar = *endpos;
48
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
277 *endpos = '\0';
126
1e65871fdfa1 2003-4-9 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
278 len += strlen (startpos);
48
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
279 if (!newval)
126
1e65871fdfa1 2003-4-9 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
280 {
1e65871fdfa1 2003-4-9 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
281 newstr = g_realloc (newstr, sizeof (char) * (len + 1));
1e65871fdfa1 2003-4-9 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
282 strcat (newstr, startpos);
1e65871fdfa1 2003-4-9 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
283 }
48
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
284 else
126
1e65871fdfa1 2003-4-9 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
285 {
298
6e0b9ca541e2 2003-10-26 Brian Masney <masneyb@gftp.org>
masneyb
parents: 292
diff changeset
286 utf8 = gftp_string_from_utf8 (request, newval);
6e0b9ca541e2 2003-10-26 Brian Masney <masneyb@gftp.org>
masneyb
parents: 292
diff changeset
287 if (utf8 != NULL)
6e0b9ca541e2 2003-10-26 Brian Masney <masneyb@gftp.org>
masneyb
parents: 292
diff changeset
288 len += strlen (utf8);
6e0b9ca541e2 2003-10-26 Brian Masney <masneyb@gftp.org>
masneyb
parents: 292
diff changeset
289 else
6e0b9ca541e2 2003-10-26 Brian Masney <masneyb@gftp.org>
masneyb
parents: 292
diff changeset
290 len += strlen (newval);
6e0b9ca541e2 2003-10-26 Brian Masney <masneyb@gftp.org>
masneyb
parents: 292
diff changeset
291
126
1e65871fdfa1 2003-4-9 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
292 newstr = g_realloc (newstr, sizeof (char) * (len + 1));
1e65871fdfa1 2003-4-9 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
293 strcat (newstr, startpos);
298
6e0b9ca541e2 2003-10-26 Brian Masney <masneyb@gftp.org>
masneyb
parents: 292
diff changeset
294
6e0b9ca541e2 2003-10-26 Brian Masney <masneyb@gftp.org>
masneyb
parents: 292
diff changeset
295 if (utf8 != NULL)
6e0b9ca541e2 2003-10-26 Brian Masney <masneyb@gftp.org>
masneyb
parents: 292
diff changeset
296 {
6e0b9ca541e2 2003-10-26 Brian Masney <masneyb@gftp.org>
masneyb
parents: 292
diff changeset
297 strcat (newstr, utf8);
6e0b9ca541e2 2003-10-26 Brian Masney <masneyb@gftp.org>
masneyb
parents: 292
diff changeset
298 g_free (utf8);
6e0b9ca541e2 2003-10-26 Brian Masney <masneyb@gftp.org>
masneyb
parents: 292
diff changeset
299 }
6e0b9ca541e2 2003-10-26 Brian Masney <masneyb@gftp.org>
masneyb
parents: 292
diff changeset
300 else
6e0b9ca541e2 2003-10-26 Brian Masney <masneyb@gftp.org>
masneyb
parents: 292
diff changeset
301 strcat (newstr, newval);
126
1e65871fdfa1 2003-4-9 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
302 }
1e65871fdfa1 2003-4-9 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
303
1e65871fdfa1 2003-4-9 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
304 *endpos = savechar;
48
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
305 endpos += 3;
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
306 startpos = endpos;
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
307 }
126
1e65871fdfa1 2003-4-9 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
308
48
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
309 return (newstr);
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
310 }
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
311
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
312
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
313 static int
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 48
diff changeset
314 rfc959_getcwd (gftp_request * request)
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 48
diff changeset
315 {
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 48
diff changeset
316 char *pos, *dir;
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 48
diff changeset
317 int ret;
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 48
diff changeset
318
292
e5ce6f15290f 2003-10-19 Brian Masney <masneyb@gftp.org>
masneyb
parents: 288
diff changeset
319 ret = rfc959_send_command (request, "PWD\r\n", 1);
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 48
diff changeset
320 if (ret < 0)
84
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
321 return (ret);
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 48
diff changeset
322 else if (ret != '2')
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 48
diff changeset
323 {
186
13ca1defdc75 2003-6-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 182
diff changeset
324 request->logging_function (gftp_logging_error, request,
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 48
diff changeset
325 _("Received invalid response to PWD command: '%s'\n"),
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 48
diff changeset
326 request->last_ftp_response);
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 48
diff changeset
327 gftp_disconnect (request);
84
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
328 return (GFTP_ERETRYABLE);
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 48
diff changeset
329 }
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 48
diff changeset
330
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 48
diff changeset
331 if ((pos = strchr (request->last_ftp_response, '"')) == NULL)
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 48
diff changeset
332 {
186
13ca1defdc75 2003-6-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 182
diff changeset
333 request->logging_function (gftp_logging_error, request,
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 48
diff changeset
334 _("Received invalid response to PWD command: '%s'\n"),
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 48
diff changeset
335 request->last_ftp_response);
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 48
diff changeset
336 gftp_disconnect (request);
84
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
337 return (GFTP_EFATAL);
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 48
diff changeset
338 }
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 48
diff changeset
339
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 48
diff changeset
340 dir = pos + 1;
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 48
diff changeset
341
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 48
diff changeset
342 if ((pos = strchr (dir, '"')) == NULL)
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 48
diff changeset
343 {
186
13ca1defdc75 2003-6-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 182
diff changeset
344 request->logging_function (gftp_logging_error, request,
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 48
diff changeset
345 _("Received invalid response to PWD command: '%s'\n"),
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 48
diff changeset
346 request->last_ftp_response);
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 48
diff changeset
347 gftp_disconnect (request);
84
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
348 return (GFTP_EFATAL);
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 48
diff changeset
349 }
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 48
diff changeset
350
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 48
diff changeset
351 *pos = '\0';
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 48
diff changeset
352
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 48
diff changeset
353 if (request->directory)
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 48
diff changeset
354 g_free (request->directory);
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 48
diff changeset
355
105
ae13b18c9336 2003-2-9 Brian Masney <masneyb@gftp.org>
masneyb
parents: 91
diff changeset
356 request->directory = g_strdup (dir);
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 48
diff changeset
357 return (0);
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 48
diff changeset
358 }
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 48
diff changeset
359
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 48
diff changeset
360
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 48
diff changeset
361 static int
48
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
362 rfc959_chdir (gftp_request * request, const char *directory)
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
363 {
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 48
diff changeset
364 char ret, *tempstr;
84
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
365 int r;
48
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
366
84
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
367 g_return_val_if_fail (request != NULL, GFTP_EFATAL);
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
368 g_return_val_if_fail (request->protonum == GFTP_FTP_NUM, GFTP_EFATAL);
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
369 g_return_val_if_fail (directory != NULL, GFTP_EFATAL);
48
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
370
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
371 if (strcmp (directory, "..") == 0)
292
e5ce6f15290f 2003-10-19 Brian Masney <masneyb@gftp.org>
masneyb
parents: 288
diff changeset
372 ret = rfc959_send_command (request, "CDUP\r\n", 1);
48
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
373 else
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
374 {
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
375 tempstr = g_strconcat ("CWD ", directory, "\r\n", NULL);
292
e5ce6f15290f 2003-10-19 Brian Masney <masneyb@gftp.org>
masneyb
parents: 288
diff changeset
376 ret = rfc959_send_command (request, tempstr, 1);
48
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
377 g_free (tempstr);
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
378 }
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
379
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
380 if (ret != '2')
84
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
381 return (GFTP_ERETRYABLE);
48
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
382
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
383 if (directory != request->directory)
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
384 {
84
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
385 if ((r = rfc959_getcwd (request)) < 0)
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
386 return (r);
48
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
387 }
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
388
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
389 return (0);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
390 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
391
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
392
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
393 static int
91
8c37d73d3f1f 2003-1-21 Brian Masney <masneyb@gftp.org>
masneyb
parents: 84
diff changeset
394 rfc959_syst (gftp_request * request)
8c37d73d3f1f 2003-1-21 Brian Masney <masneyb@gftp.org>
masneyb
parents: 84
diff changeset
395 {
8c37d73d3f1f 2003-1-21 Brian Masney <masneyb@gftp.org>
masneyb
parents: 84
diff changeset
396 char *stpos, *endpos;
8c37d73d3f1f 2003-1-21 Brian Masney <masneyb@gftp.org>
masneyb
parents: 84
diff changeset
397 int ret;
8c37d73d3f1f 2003-1-21 Brian Masney <masneyb@gftp.org>
masneyb
parents: 84
diff changeset
398
8c37d73d3f1f 2003-1-21 Brian Masney <masneyb@gftp.org>
masneyb
parents: 84
diff changeset
399 g_return_val_if_fail (request != NULL, GFTP_EFATAL);
8c37d73d3f1f 2003-1-21 Brian Masney <masneyb@gftp.org>
masneyb
parents: 84
diff changeset
400 g_return_val_if_fail (request->protonum == GFTP_FTP_NUM, GFTP_EFATAL);
169
d40f9db52cdf 2003-6-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 168
diff changeset
401 g_return_val_if_fail (request->datafd > 0, GFTP_EFATAL);
91
8c37d73d3f1f 2003-1-21 Brian Masney <masneyb@gftp.org>
masneyb
parents: 84
diff changeset
402
292
e5ce6f15290f 2003-10-19 Brian Masney <masneyb@gftp.org>
masneyb
parents: 288
diff changeset
403 ret = rfc959_send_command (request, "SYST\r\n", 1);
91
8c37d73d3f1f 2003-1-21 Brian Masney <masneyb@gftp.org>
masneyb
parents: 84
diff changeset
404
8c37d73d3f1f 2003-1-21 Brian Masney <masneyb@gftp.org>
masneyb
parents: 84
diff changeset
405 if (ret < 0)
8c37d73d3f1f 2003-1-21 Brian Masney <masneyb@gftp.org>
masneyb
parents: 84
diff changeset
406 return (ret);
8c37d73d3f1f 2003-1-21 Brian Masney <masneyb@gftp.org>
masneyb
parents: 84
diff changeset
407 else if (ret != '2')
8c37d73d3f1f 2003-1-21 Brian Masney <masneyb@gftp.org>
masneyb
parents: 84
diff changeset
408 return (GFTP_ERETRYABLE);
8c37d73d3f1f 2003-1-21 Brian Masney <masneyb@gftp.org>
masneyb
parents: 84
diff changeset
409
8c37d73d3f1f 2003-1-21 Brian Masney <masneyb@gftp.org>
masneyb
parents: 84
diff changeset
410 if ((stpos = strchr (request->last_ftp_response, ' ')) == NULL)
8c37d73d3f1f 2003-1-21 Brian Masney <masneyb@gftp.org>
masneyb
parents: 84
diff changeset
411 return (GFTP_ERETRYABLE);
8c37d73d3f1f 2003-1-21 Brian Masney <masneyb@gftp.org>
masneyb
parents: 84
diff changeset
412
114
fe36ed90aedd 2003-2-23 Brian Masney <masneyb@gftp.org>
masneyb
parents: 107
diff changeset
413 stpos++;
fe36ed90aedd 2003-2-23 Brian Masney <masneyb@gftp.org>
masneyb
parents: 107
diff changeset
414
91
8c37d73d3f1f 2003-1-21 Brian Masney <masneyb@gftp.org>
masneyb
parents: 84
diff changeset
415 if ((endpos = strchr (stpos, ' ')) == NULL)
8c37d73d3f1f 2003-1-21 Brian Masney <masneyb@gftp.org>
masneyb
parents: 84
diff changeset
416 return (GFTP_ERETRYABLE);
8c37d73d3f1f 2003-1-21 Brian Masney <masneyb@gftp.org>
masneyb
parents: 84
diff changeset
417
8c37d73d3f1f 2003-1-21 Brian Masney <masneyb@gftp.org>
masneyb
parents: 84
diff changeset
418 *endpos = '\0';
8c37d73d3f1f 2003-1-21 Brian Masney <masneyb@gftp.org>
masneyb
parents: 84
diff changeset
419 if (strcmp (stpos, "UNIX") == 0)
122
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 114
diff changeset
420 request->server_type = GFTP_DIRTYPE_UNIX;
107
982e3890e7fe 2003-2-17 Brian Masney <masneyb@gftp.org>
masneyb
parents: 105
diff changeset
421 else if (strcmp (stpos, "VMS") == 0)
122
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 114
diff changeset
422 request->server_type = GFTP_DIRTYPE_VMS;
305
6d180e6a8ba5 2003-11-3 Brian Masney <masneyb@gftp.org>
masneyb
parents: 301
diff changeset
423 else if (strcmp (stpos, "NETWARE") == 0)
6d180e6a8ba5 2003-11-3 Brian Masney <masneyb@gftp.org>
masneyb
parents: 301
diff changeset
424 request->server_type = GFTP_DIRTYPE_NOVELL;
136
84b3e69807a2 2003-4-18 Brian Masney <masneyb@gftp.org>
masneyb
parents: 126
diff changeset
425 else if (strcmp (stpos, "CRAY") == 0)
84b3e69807a2 2003-4-18 Brian Masney <masneyb@gftp.org>
masneyb
parents: 126
diff changeset
426 request->server_type = GFTP_DIRTYPE_CRAY;
91
8c37d73d3f1f 2003-1-21 Brian Masney <masneyb@gftp.org>
masneyb
parents: 84
diff changeset
427 else
122
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 114
diff changeset
428 request->server_type = GFTP_DIRTYPE_OTHER;
91
8c37d73d3f1f 2003-1-21 Brian Masney <masneyb@gftp.org>
masneyb
parents: 84
diff changeset
429
8c37d73d3f1f 2003-1-21 Brian Masney <masneyb@gftp.org>
masneyb
parents: 84
diff changeset
430 return (0);
8c37d73d3f1f 2003-1-21 Brian Masney <masneyb@gftp.org>
masneyb
parents: 84
diff changeset
431 }
8c37d73d3f1f 2003-1-21 Brian Masney <masneyb@gftp.org>
masneyb
parents: 84
diff changeset
432
8c37d73d3f1f 2003-1-21 Brian Masney <masneyb@gftp.org>
masneyb
parents: 84
diff changeset
433
8c37d73d3f1f 2003-1-21 Brian Masney <masneyb@gftp.org>
masneyb
parents: 84
diff changeset
434 static int
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
435 rfc959_connect (gftp_request * request)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
436 {
298
6e0b9ca541e2 2003-10-26 Brian Masney <masneyb@gftp.org>
masneyb
parents: 292
diff changeset
437 char tempchar, *startpos, *endpos, *tempstr, *email, *proxy_hostname, *utf8;
325
0fcc6468a0af 2003-12-4 Brian Masney <masneyb@gftp.org>
masneyb
parents: 319
diff changeset
438 int ret, resp;
0fcc6468a0af 2003-12-4 Brian Masney <masneyb@gftp.org>
masneyb
parents: 319
diff changeset
439 intptr_t ascii_transfers, proxy_port;
122
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 114
diff changeset
440 rfc959_parms * parms;
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
441
84
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
442 g_return_val_if_fail (request != NULL, GFTP_EFATAL);
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
443 g_return_val_if_fail (request->protonum == GFTP_FTP_NUM, GFTP_EFATAL);
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
444 g_return_val_if_fail (request->hostname != NULL, GFTP_EFATAL);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
445
169
d40f9db52cdf 2003-6-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 168
diff changeset
446 if (request->datafd > 0)
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 48
diff changeset
447 return (0);
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 48
diff changeset
448
122
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 114
diff changeset
449 parms = request->protocol_data;
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 114
diff changeset
450
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 114
diff changeset
451 gftp_lookup_request_option (request, "email", &email);
124
65048c959029 2003-4-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 122
diff changeset
452 gftp_lookup_request_option (request, "ftp_proxy_host", &proxy_hostname);
65048c959029 2003-4-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 122
diff changeset
453 gftp_lookup_request_option (request, "ftp_proxy_port", &proxy_port);
122
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 114
diff changeset
454
7
5551ab2301fe * Fixed a DND crash
masneyb
parents: 1
diff changeset
455 if (request->username == NULL || *request->username == '\0')
5551ab2301fe * Fixed a DND crash
masneyb
parents: 1
diff changeset
456 {
5551ab2301fe * Fixed a DND crash
masneyb
parents: 1
diff changeset
457 gftp_set_username (request, "anonymous");
122
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 114
diff changeset
458 gftp_set_password (request, email);
7
5551ab2301fe * Fixed a DND crash
masneyb
parents: 1
diff changeset
459 }
5551ab2301fe * Fixed a DND crash
masneyb
parents: 1
diff changeset
460 else if (strcasecmp (request->username, "anonymous") == 0)
122
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 114
diff changeset
461 gftp_set_password (request, email);
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 114
diff changeset
462
177
aec4b4541d3a 2003-6-9 Brian Masney <masneyb@gftp.org>
masneyb
parents: 173
diff changeset
463 if ((ret = gftp_connect_server (request, "ftp", proxy_hostname, proxy_port)) < 0)
aec4b4541d3a 2003-6-9 Brian Masney <masneyb@gftp.org>
masneyb
parents: 173
diff changeset
464 return (ret);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
465
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
466 /* Get the banner */
292
e5ce6f15290f 2003-10-19 Brian Masney <masneyb@gftp.org>
masneyb
parents: 288
diff changeset
467 if ((ret = rfc959_read_response (request, 1)) != '2')
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
468 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
469 gftp_disconnect (request);
84
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
470 return (ret);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
471 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
472
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
473 /* Login the proxy server if available */
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
474 if (request->use_proxy)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
475 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
476 resp = '3';
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
477 startpos = endpos = tempstr = parse_ftp_proxy_string (request);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
478 while ((resp == '3' || resp == '2') && *startpos != '\0')
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
479 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
480 if (*endpos == '\n' || *endpos == '\0')
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
481 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
482 tempchar = *(endpos + 1);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
483 if (*endpos != '\0')
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
484 *(endpos + 1) = '\0';
292
e5ce6f15290f 2003-10-19 Brian Masney <masneyb@gftp.org>
masneyb
parents: 288
diff changeset
485 if ((resp = rfc959_send_command (request, startpos, 1)) < 0)
84
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
486 return (resp);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
487 if (*endpos != '\0')
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
488 *(endpos + 1) = tempchar;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
489 else
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
490 break;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
491 startpos = endpos + 1;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
492 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
493 endpos++;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
494 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
495 g_free (tempstr);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
496 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
497 else
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
498 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
499 tempstr = g_strconcat ("USER ", request->username, "\r\n", NULL);
292
e5ce6f15290f 2003-10-19 Brian Masney <masneyb@gftp.org>
masneyb
parents: 288
diff changeset
500 resp = rfc959_send_command (request, tempstr, 1);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
501 g_free (tempstr);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
502 if (resp < 0)
84
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
503 return (GFTP_ERETRYABLE);
286
de030cbd432c 2003-10-12 Brian Masney <masneyb@gftp.org>
masneyb
parents: 278
diff changeset
504
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
505 if (resp == '3')
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
506 {
298
6e0b9ca541e2 2003-10-26 Brian Masney <masneyb@gftp.org>
masneyb
parents: 292
diff changeset
507 utf8 = gftp_string_from_utf8 (request, request->password);
6e0b9ca541e2 2003-10-26 Brian Masney <masneyb@gftp.org>
masneyb
parents: 292
diff changeset
508 if (utf8 != NULL)
6e0b9ca541e2 2003-10-26 Brian Masney <masneyb@gftp.org>
masneyb
parents: 292
diff changeset
509 {
6e0b9ca541e2 2003-10-26 Brian Masney <masneyb@gftp.org>
masneyb
parents: 292
diff changeset
510 tempstr = g_strconcat ("PASS ", utf8, "\r\n", NULL);
6e0b9ca541e2 2003-10-26 Brian Masney <masneyb@gftp.org>
masneyb
parents: 292
diff changeset
511 g_free (utf8);
6e0b9ca541e2 2003-10-26 Brian Masney <masneyb@gftp.org>
masneyb
parents: 292
diff changeset
512 }
6e0b9ca541e2 2003-10-26 Brian Masney <masneyb@gftp.org>
masneyb
parents: 292
diff changeset
513 else
6e0b9ca541e2 2003-10-26 Brian Masney <masneyb@gftp.org>
masneyb
parents: 292
diff changeset
514 tempstr = g_strconcat ("PASS ", request->password, "\r\n", NULL);
6e0b9ca541e2 2003-10-26 Brian Masney <masneyb@gftp.org>
masneyb
parents: 292
diff changeset
515
292
e5ce6f15290f 2003-10-19 Brian Masney <masneyb@gftp.org>
masneyb
parents: 288
diff changeset
516 resp = rfc959_send_command (request, tempstr, 1);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
517 g_free (tempstr);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
518 if (resp < 0)
84
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
519 return (GFTP_ERETRYABLE);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
520 }
286
de030cbd432c 2003-10-12 Brian Masney <masneyb@gftp.org>
masneyb
parents: 278
diff changeset
521
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
522 if (resp == '3' && request->account)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
523 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
524 tempstr = g_strconcat ("ACCT ", request->account, "\r\n", NULL);
292
e5ce6f15290f 2003-10-19 Brian Masney <masneyb@gftp.org>
masneyb
parents: 288
diff changeset
525 resp = rfc959_send_command (request, tempstr, 1);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
526 g_free (tempstr);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
527 if (resp < 0)
84
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
528 return (GFTP_ERETRYABLE);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
529 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
530 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
531
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
532 if (resp != '2')
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
533 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
534 gftp_disconnect (request);
286
de030cbd432c 2003-10-12 Brian Masney <masneyb@gftp.org>
masneyb
parents: 278
diff changeset
535
de030cbd432c 2003-10-12 Brian Masney <masneyb@gftp.org>
masneyb
parents: 278
diff changeset
536 if (resp == '5')
de030cbd432c 2003-10-12 Brian Masney <masneyb@gftp.org>
masneyb
parents: 278
diff changeset
537 return (GFTP_EFATAL);
de030cbd432c 2003-10-12 Brian Masney <masneyb@gftp.org>
masneyb
parents: 278
diff changeset
538 else
de030cbd432c 2003-10-12 Brian Masney <masneyb@gftp.org>
masneyb
parents: 278
diff changeset
539 return (GFTP_ERETRYABLE);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
540 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
541
169
d40f9db52cdf 2003-6-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 168
diff changeset
542 if ((ret = rfc959_syst (request)) < 0 && request->datafd < 0)
91
8c37d73d3f1f 2003-1-21 Brian Masney <masneyb@gftp.org>
masneyb
parents: 84
diff changeset
543 return (ret);
8c37d73d3f1f 2003-1-21 Brian Masney <masneyb@gftp.org>
masneyb
parents: 84
diff changeset
544
122
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 114
diff changeset
545 gftp_lookup_request_option (request, "ascii_transfers", &ascii_transfers);
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 114
diff changeset
546 if (ascii_transfers)
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 114
diff changeset
547 {
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 114
diff changeset
548 tempstr = "TYPE A\r\n";
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 114
diff changeset
549 parms->is_ascii_transfer = 1;
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 114
diff changeset
550 }
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
551 else
122
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 114
diff changeset
552 {
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 114
diff changeset
553 tempstr = "TYPE I\r\n";
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 114
diff changeset
554 parms->is_ascii_transfer = 0;
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 114
diff changeset
555 }
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
556
292
e5ce6f15290f 2003-10-19 Brian Masney <masneyb@gftp.org>
masneyb
parents: 288
diff changeset
557 if ((ret = rfc959_send_command (request, tempstr, 1)) < 0)
84
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
558 return (ret);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
559
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
560 ret = -1;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
561 if (request->directory != NULL && *request->directory != '\0')
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
562 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
563 ret = rfc959_chdir (request, request->directory);
169
d40f9db52cdf 2003-6-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 168
diff changeset
564 if (request->datafd < 0)
84
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
565 return (ret);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
566 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
567
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
568 if (ret != 0)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
569 {
84
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
570 if ((ret = rfc959_getcwd (request)) < 0)
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
571 return (ret);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
572 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
573
169
d40f9db52cdf 2003-6-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 168
diff changeset
574 if (request->datafd < 0)
84
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
575 return (GFTP_EFATAL);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
576
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
577 return (0);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
578 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
579
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
580
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
581 static void
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
582 rfc959_disconnect (gftp_request * request)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
583 {
169
d40f9db52cdf 2003-6-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 168
diff changeset
584 rfc959_parms * parms;
d40f9db52cdf 2003-6-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 168
diff changeset
585
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
586 g_return_if_fail (request != NULL);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
587 g_return_if_fail (request->protonum == GFTP_FTP_NUM);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
588
169
d40f9db52cdf 2003-6-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 168
diff changeset
589 parms = request->protocol_data;
d40f9db52cdf 2003-6-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 168
diff changeset
590
d40f9db52cdf 2003-6-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 168
diff changeset
591 if (request->datafd > 0)
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
592 {
186
13ca1defdc75 2003-6-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 182
diff changeset
593 request->logging_function (gftp_logging_misc, request,
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
594 _("Disconnecting from site %s\n"),
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
595 request->hostname);
169
d40f9db52cdf 2003-6-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 168
diff changeset
596 close (request->datafd);
d40f9db52cdf 2003-6-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 168
diff changeset
597 request->datafd = -1;
d40f9db52cdf 2003-6-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 168
diff changeset
598 }
d40f9db52cdf 2003-6-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 168
diff changeset
599
d40f9db52cdf 2003-6-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 168
diff changeset
600 if (parms->data_connection > 0)
d40f9db52cdf 2003-6-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 168
diff changeset
601 {
d40f9db52cdf 2003-6-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 168
diff changeset
602 close (parms->data_connection);
d40f9db52cdf 2003-6-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 168
diff changeset
603 parms->data_connection = -1;
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
604 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
605 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
606
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
607
48
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
608 static int
146
782f84694489 2003-4-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 139
diff changeset
609 rfc959_ipv4_data_connection_new (gftp_request * request)
48
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
610 {
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
611 char *pos, *pos1, resp, *command;
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
612 struct sockaddr_in data_addr;
325
0fcc6468a0af 2003-12-4 Brian Masney <masneyb@gftp.org>
masneyb
parents: 319
diff changeset
613 int i;
0fcc6468a0af 2003-12-4 Brian Masney <masneyb@gftp.org>
masneyb
parents: 319
diff changeset
614 intptr_t passive_transfer;
169
d40f9db52cdf 2003-6-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 168
diff changeset
615 rfc959_parms * parms;
195
3fa7b4f4ab78 2003-6-19 Brian Masney <masneyb@gftp.org>
masneyb
parents: 186
diff changeset
616 socklen_t data_addr_len;
48
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
617 unsigned int temp[6];
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
618 unsigned char ad[6];
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
619
169
d40f9db52cdf 2003-6-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 168
diff changeset
620 parms = request->protocol_data;
d40f9db52cdf 2003-6-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 168
diff changeset
621
d40f9db52cdf 2003-6-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 168
diff changeset
622 if ((parms->data_connection = socket (AF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0)
48
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
623 {
186
13ca1defdc75 2003-6-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 182
diff changeset
624 request->logging_function (gftp_logging_error, request,
313
32a6b26b7026 2003-11-9 Brian Masney <masneyb@gftp.org>
masneyb
parents: 309
diff changeset
625 _("Failed to create a IPv4 socket: %s\n"),
48
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
626 g_strerror (errno));
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
627 gftp_disconnect (request);
84
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
628 return (GFTP_ERETRYABLE);
48
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
629 }
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
630
182
33b394ebba68 2003-6-15 Brian Masney <masneyb@gftp.org>
masneyb
parents: 177
diff changeset
631 if (fcntl (parms->data_connection, F_SETFD, 1) == -1)
33b394ebba68 2003-6-15 Brian Masney <masneyb@gftp.org>
masneyb
parents: 177
diff changeset
632 {
186
13ca1defdc75 2003-6-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 182
diff changeset
633 request->logging_function (gftp_logging_error, request,
182
33b394ebba68 2003-6-15 Brian Masney <masneyb@gftp.org>
masneyb
parents: 177
diff changeset
634 _("Error: Cannot set close on exec flag: %s\n"),
33b394ebba68 2003-6-15 Brian Masney <masneyb@gftp.org>
masneyb
parents: 177
diff changeset
635 g_strerror (errno));
33b394ebba68 2003-6-15 Brian Masney <masneyb@gftp.org>
masneyb
parents: 177
diff changeset
636
33b394ebba68 2003-6-15 Brian Masney <masneyb@gftp.org>
masneyb
parents: 177
diff changeset
637 return (GFTP_ERETRYABLE);
33b394ebba68 2003-6-15 Brian Masney <masneyb@gftp.org>
masneyb
parents: 177
diff changeset
638 }
33b394ebba68 2003-6-15 Brian Masney <masneyb@gftp.org>
masneyb
parents: 177
diff changeset
639
48
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
640 data_addr_len = sizeof (data_addr);
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
641 memset (&data_addr, 0, data_addr_len);
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
642 data_addr.sin_family = AF_INET;
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
643
122
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 114
diff changeset
644 gftp_lookup_request_option (request, "passive_transfer", &passive_transfer);
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 114
diff changeset
645 if (passive_transfer)
48
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
646 {
292
e5ce6f15290f 2003-10-19 Brian Masney <masneyb@gftp.org>
masneyb
parents: 288
diff changeset
647 if ((resp = rfc959_send_command (request, "PASV\r\n", 1)) != '2')
48
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
648 {
169
d40f9db52cdf 2003-6-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 168
diff changeset
649 if (request->datafd < 0)
288
c8627e70adb5 2003-10-17 Brian Masney <masneyb@gftp.org>
masneyb
parents: 286
diff changeset
650 return (GFTP_ERETRYABLE);
48
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
651
122
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 114
diff changeset
652 gftp_set_request_option (request, "passive_transfer", GINT_TO_POINTER(0));
146
782f84694489 2003-4-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 139
diff changeset
653 return (rfc959_ipv4_data_connection_new (request));
48
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
654 }
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 48
diff changeset
655
48
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
656 pos = request->last_ftp_response + 4;
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
657 while (!isdigit ((int) *pos) && *pos != '\0')
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
658 pos++;
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 48
diff changeset
659
48
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
660 if (*pos == '\0')
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
661 {
186
13ca1defdc75 2003-6-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 182
diff changeset
662 request->logging_function (gftp_logging_error, request,
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 48
diff changeset
663 _("Cannot find an IP address in PASV response '%s'\n"),
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 48
diff changeset
664 request->last_ftp_response);
48
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
665 gftp_disconnect (request);
84
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
666 return (GFTP_EFATAL);
48
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
667 }
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 48
diff changeset
668
48
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
669 if (sscanf (pos, "%u,%u,%u,%u,%u,%u", &temp[0], &temp[1], &temp[2],
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
670 &temp[3], &temp[4], &temp[5]) != 6)
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
671 {
186
13ca1defdc75 2003-6-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 182
diff changeset
672 request->logging_function (gftp_logging_error, request,
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 48
diff changeset
673 _("Cannot find an IP address in PASV response '%s'\n"),
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 48
diff changeset
674 request->last_ftp_response);
48
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
675 gftp_disconnect (request);
84
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
676 return (GFTP_EFATAL);
48
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
677 }
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 48
diff changeset
678
48
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
679 for (i = 0; i < 6; i++)
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
680 ad[i] = (unsigned char) (temp[i] & 0xff);
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
681
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
682 memcpy (&data_addr.sin_addr, &ad[0], 4);
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
683 memcpy (&data_addr.sin_port, &ad[4], 2);
169
d40f9db52cdf 2003-6-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 168
diff changeset
684 if (connect (parms->data_connection, (struct sockaddr *) &data_addr,
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 48
diff changeset
685 data_addr_len) == -1)
48
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
686 {
186
13ca1defdc75 2003-6-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 182
diff changeset
687 request->logging_function (gftp_logging_error, request,
48
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
688 _("Cannot create a data connection: %s\n"),
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
689 g_strerror (errno));
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
690 gftp_disconnect (request);
84
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
691 return (GFTP_ERETRYABLE);
48
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
692 }
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
693 }
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
694 else
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
695 {
169
d40f9db52cdf 2003-6-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 168
diff changeset
696 if (getsockname (request->datafd, (struct sockaddr *) &data_addr,
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 48
diff changeset
697 &data_addr_len) == -1)
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 48
diff changeset
698 {
186
13ca1defdc75 2003-6-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 182
diff changeset
699 request->logging_function (gftp_logging_error, request,
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 48
diff changeset
700 _("Cannot get socket name: %s\n"),
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 48
diff changeset
701 g_strerror (errno));
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 48
diff changeset
702 gftp_disconnect (request);
84
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
703 return (GFTP_ERETRYABLE);
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 48
diff changeset
704 }
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 48
diff changeset
705
48
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
706 data_addr.sin_port = 0;
169
d40f9db52cdf 2003-6-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 168
diff changeset
707 if (bind (parms->data_connection, (struct sockaddr *) &data_addr,
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 48
diff changeset
708 data_addr_len) == -1)
48
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
709 {
186
13ca1defdc75 2003-6-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 182
diff changeset
710 request->logging_function (gftp_logging_error, request,
48
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
711 _("Cannot bind a port: %s\n"),
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
712 g_strerror (errno));
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
713 gftp_disconnect (request);
84
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
714 return (GFTP_ERETRYABLE);
48
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
715 }
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
716
169
d40f9db52cdf 2003-6-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 168
diff changeset
717 if (getsockname (parms->data_connection, (struct sockaddr *) &data_addr,
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 48
diff changeset
718 &data_addr_len) == -1)
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 48
diff changeset
719 {
186
13ca1defdc75 2003-6-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 182
diff changeset
720 request->logging_function (gftp_logging_error, request,
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 48
diff changeset
721 _("Cannot get socket name: %s\n"),
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 48
diff changeset
722 g_strerror (errno));
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 48
diff changeset
723 gftp_disconnect (request);
84
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
724 return (GFTP_ERETRYABLE);
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 48
diff changeset
725 }
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 48
diff changeset
726
169
d40f9db52cdf 2003-6-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 168
diff changeset
727 if (listen (parms->data_connection, 1) == -1)
48
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
728 {
186
13ca1defdc75 2003-6-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 182
diff changeset
729 request->logging_function (gftp_logging_error, request,
48
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
730 _("Cannot listen on port %d: %s\n"),
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
731 ntohs (data_addr.sin_port),
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
732 g_strerror (errno));
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
733 gftp_disconnect (request);
84
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
734 return (GFTP_ERETRYABLE);
48
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
735 }
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 48
diff changeset
736
48
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
737 pos = (char *) &data_addr.sin_addr;
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
738 pos1 = (char *) &data_addr.sin_port;
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
739 command = g_strdup_printf ("PORT %u,%u,%u,%u,%u,%u\r\n",
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
740 pos[0] & 0xff, pos[1] & 0xff, pos[2] & 0xff,
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
741 pos[3] & 0xff, pos1[0] & 0xff,
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
742 pos1[1] & 0xff);
292
e5ce6f15290f 2003-10-19 Brian Masney <masneyb@gftp.org>
masneyb
parents: 288
diff changeset
743 resp = rfc959_send_command (request, command, 1);
48
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
744 g_free (command);
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
745 if (resp != '2')
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
746 {
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
747 gftp_disconnect (request);
84
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
748 return (GFTP_ERETRYABLE);
48
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
749 }
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
750 }
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
751
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
752 return (0);
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
753 }
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
754
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
755
146
782f84694489 2003-4-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 139
diff changeset
756 #ifdef HAVE_IPV6
782f84694489 2003-4-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 139
diff changeset
757
782f84694489 2003-4-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 139
diff changeset
758 static int
782f84694489 2003-4-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 139
diff changeset
759 rfc959_ipv6_data_connection_new (gftp_request * request)
782f84694489 2003-4-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 139
diff changeset
760 {
782f84694489 2003-4-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 139
diff changeset
761 char *pos, resp, buf[64], *command;
782f84694489 2003-4-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 139
diff changeset
762 struct sockaddr_in6 data_addr;
782f84694489 2003-4-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 139
diff changeset
763 int passive_transfer;
195
3fa7b4f4ab78 2003-6-19 Brian Masney <masneyb@gftp.org>
masneyb
parents: 186
diff changeset
764 socklen_t data_addr_len;
169
d40f9db52cdf 2003-6-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 168
diff changeset
765 rfc959_parms * parms;
146
782f84694489 2003-4-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 139
diff changeset
766 unsigned int port;
782f84694489 2003-4-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 139
diff changeset
767
169
d40f9db52cdf 2003-6-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 168
diff changeset
768 parms = request->protocol_data;
d40f9db52cdf 2003-6-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 168
diff changeset
769 if ((parms->data_connection = socket (AF_INET6, SOCK_STREAM, IPPROTO_TCP)) < 0)
146
782f84694489 2003-4-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 139
diff changeset
770 {
186
13ca1defdc75 2003-6-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 182
diff changeset
771 request->logging_function (gftp_logging_error, request,
313
32a6b26b7026 2003-11-9 Brian Masney <masneyb@gftp.org>
masneyb
parents: 309
diff changeset
772 _("Failed to create a IPv6 socket: %s\n"),
146
782f84694489 2003-4-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 139
diff changeset
773 g_strerror (errno));
782f84694489 2003-4-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 139
diff changeset
774 gftp_disconnect (request);
782f84694489 2003-4-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 139
diff changeset
775 return (GFTP_ERETRYABLE);
782f84694489 2003-4-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 139
diff changeset
776 }
782f84694489 2003-4-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 139
diff changeset
777
182
33b394ebba68 2003-6-15 Brian Masney <masneyb@gftp.org>
masneyb
parents: 177
diff changeset
778 if (fcntl (parms->data_connection, F_SETFD, 1) == -1)
33b394ebba68 2003-6-15 Brian Masney <masneyb@gftp.org>
masneyb
parents: 177
diff changeset
779 {
186
13ca1defdc75 2003-6-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 182
diff changeset
780 request->logging_function (gftp_logging_error, request,
182
33b394ebba68 2003-6-15 Brian Masney <masneyb@gftp.org>
masneyb
parents: 177
diff changeset
781 _("Error: Cannot set close on exec flag: %s\n"),
33b394ebba68 2003-6-15 Brian Masney <masneyb@gftp.org>
masneyb
parents: 177
diff changeset
782 g_strerror (errno));
33b394ebba68 2003-6-15 Brian Masney <masneyb@gftp.org>
masneyb
parents: 177
diff changeset
783
33b394ebba68 2003-6-15 Brian Masney <masneyb@gftp.org>
masneyb
parents: 177
diff changeset
784 return (GFTP_ERETRYABLE);
33b394ebba68 2003-6-15 Brian Masney <masneyb@gftp.org>
masneyb
parents: 177
diff changeset
785 }
33b394ebba68 2003-6-15 Brian Masney <masneyb@gftp.org>
masneyb
parents: 177
diff changeset
786
146
782f84694489 2003-4-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 139
diff changeset
787 data_addr_len = sizeof (data_addr);
782f84694489 2003-4-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 139
diff changeset
788 /* This condition shouldn't happen. We better check anyway... */
782f84694489 2003-4-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 139
diff changeset
789 if (data_addr_len != request->hostp->ai_addrlen)
782f84694489 2003-4-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 139
diff changeset
790 {
186
13ca1defdc75 2003-6-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 182
diff changeset
791 request->logging_function (gftp_logging_error, request,
146
782f84694489 2003-4-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 139
diff changeset
792 _("Error: It doesn't look like we are connected via IPv6. Aborting connection.\n"));
782f84694489 2003-4-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 139
diff changeset
793 gftp_disconnect (request);
782f84694489 2003-4-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 139
diff changeset
794 return (GFTP_EFATAL);
782f84694489 2003-4-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 139
diff changeset
795 }
782f84694489 2003-4-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 139
diff changeset
796
782f84694489 2003-4-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 139
diff changeset
797 memset (&data_addr, 0, data_addr_len);
782f84694489 2003-4-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 139
diff changeset
798 data_addr.sin6_family = AF_INET6;
782f84694489 2003-4-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 139
diff changeset
799
782f84694489 2003-4-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 139
diff changeset
800 gftp_lookup_request_option (request, "passive_transfer", &passive_transfer);
782f84694489 2003-4-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 139
diff changeset
801 if (passive_transfer)
782f84694489 2003-4-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 139
diff changeset
802 {
292
e5ce6f15290f 2003-10-19 Brian Masney <masneyb@gftp.org>
masneyb
parents: 288
diff changeset
803 if ((resp = rfc959_send_command (request, "EPSV\r\n", 1)) != '2')
146
782f84694489 2003-4-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 139
diff changeset
804 {
169
d40f9db52cdf 2003-6-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 168
diff changeset
805 if (request->datafd < 0)
288
c8627e70adb5 2003-10-17 Brian Masney <masneyb@gftp.org>
masneyb
parents: 286
diff changeset
806 return (GFTP_ERETRYABLE);
146
782f84694489 2003-4-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 139
diff changeset
807
782f84694489 2003-4-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 139
diff changeset
808 gftp_set_request_option (request, "passive_transfer",
782f84694489 2003-4-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 139
diff changeset
809 GINT_TO_POINTER(0));
782f84694489 2003-4-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 139
diff changeset
810 return (rfc959_ipv6_data_connection_new (request));
782f84694489 2003-4-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 139
diff changeset
811 }
782f84694489 2003-4-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 139
diff changeset
812
782f84694489 2003-4-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 139
diff changeset
813 pos = request->last_ftp_response + 4;
782f84694489 2003-4-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 139
diff changeset
814 while (*pos != '(' && *pos != '\0')
782f84694489 2003-4-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 139
diff changeset
815 pos++;
782f84694489 2003-4-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 139
diff changeset
816 pos++;
782f84694489 2003-4-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 139
diff changeset
817
782f84694489 2003-4-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 139
diff changeset
818 if (*pos == '\0')
782f84694489 2003-4-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 139
diff changeset
819 {
186
13ca1defdc75 2003-6-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 182
diff changeset
820 request->logging_function (gftp_logging_error, request,
146
782f84694489 2003-4-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 139
diff changeset
821 _("Invalid EPSV response '%s'\n"),
782f84694489 2003-4-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 139
diff changeset
822 request->last_ftp_response);
782f84694489 2003-4-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 139
diff changeset
823 gftp_disconnect (request);
782f84694489 2003-4-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 139
diff changeset
824 return (GFTP_EFATAL);
782f84694489 2003-4-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 139
diff changeset
825 }
782f84694489 2003-4-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 139
diff changeset
826
319
2ad0b9a00fdd 2003-11-23 Brian Masney <masneyb@gftp.org>
masneyb
parents: 313
diff changeset
827 if (sscanf (pos, "|||%u|", &port) != 1)
146
782f84694489 2003-4-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 139
diff changeset
828 {
186
13ca1defdc75 2003-6-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 182
diff changeset
829 request->logging_function (gftp_logging_error, request,
146
782f84694489 2003-4-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 139
diff changeset
830 _("Invalid EPSV response '%s'\n"),
782f84694489 2003-4-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 139
diff changeset
831 request->last_ftp_response);
782f84694489 2003-4-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 139
diff changeset
832 gftp_disconnect (request);
782f84694489 2003-4-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 139
diff changeset
833 return (GFTP_EFATAL);
782f84694489 2003-4-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 139
diff changeset
834 }
782f84694489 2003-4-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 139
diff changeset
835
782f84694489 2003-4-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 139
diff changeset
836 memcpy (&data_addr, request->hostp->ai_addr, data_addr_len);
782f84694489 2003-4-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 139
diff changeset
837 data_addr.sin6_port = htons (port);
782f84694489 2003-4-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 139
diff changeset
838
169
d40f9db52cdf 2003-6-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 168
diff changeset
839 if (connect (parms->data_connection, (struct sockaddr *) &data_addr,
146
782f84694489 2003-4-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 139
diff changeset
840 data_addr_len) == -1)
782f84694489 2003-4-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 139
diff changeset
841 {
186
13ca1defdc75 2003-6-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 182
diff changeset
842 request->logging_function (gftp_logging_error, request,
146
782f84694489 2003-4-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 139
diff changeset
843 _("Cannot create a data connection: %s\n"),
782f84694489 2003-4-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 139
diff changeset
844 g_strerror (errno));
782f84694489 2003-4-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 139
diff changeset
845 gftp_disconnect (request);
782f84694489 2003-4-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 139
diff changeset
846 return (GFTP_ERETRYABLE);
782f84694489 2003-4-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 139
diff changeset
847 }
782f84694489 2003-4-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 139
diff changeset
848 }
782f84694489 2003-4-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 139
diff changeset
849 else
782f84694489 2003-4-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 139
diff changeset
850 {
782f84694489 2003-4-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 139
diff changeset
851 memcpy (&data_addr, request->hostp->ai_addr, data_addr_len);
782f84694489 2003-4-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 139
diff changeset
852 data_addr.sin6_port = 0;
782f84694489 2003-4-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 139
diff changeset
853
169
d40f9db52cdf 2003-6-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 168
diff changeset
854 if (bind (parms->data_connection, (struct sockaddr *) &data_addr,
146
782f84694489 2003-4-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 139
diff changeset
855 data_addr_len) == -1)
782f84694489 2003-4-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 139
diff changeset
856 {
186
13ca1defdc75 2003-6-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 182
diff changeset
857 request->logging_function (gftp_logging_error, request,
146
782f84694489 2003-4-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 139
diff changeset
858 _("Cannot bind a port: %s\n"),
782f84694489 2003-4-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 139
diff changeset
859 g_strerror (errno));
782f84694489 2003-4-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 139
diff changeset
860 gftp_disconnect (request);
782f84694489 2003-4-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 139
diff changeset
861 return (GFTP_ERETRYABLE);
782f84694489 2003-4-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 139
diff changeset
862 }
782f84694489 2003-4-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 139
diff changeset
863
169
d40f9db52cdf 2003-6-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 168
diff changeset
864 if (getsockname (parms->data_connection, (struct sockaddr *) &data_addr,
146
782f84694489 2003-4-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 139
diff changeset
865 &data_addr_len) == -1)
782f84694489 2003-4-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 139
diff changeset
866 {
186
13ca1defdc75 2003-6-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 182
diff changeset
867 request->logging_function (gftp_logging_error, request,
146
782f84694489 2003-4-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 139
diff changeset
868 _("Cannot get socket name: %s\n"),
782f84694489 2003-4-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 139
diff changeset
869 g_strerror (errno));
782f84694489 2003-4-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 139
diff changeset
870 gftp_disconnect (request);
782f84694489 2003-4-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 139
diff changeset
871 return (GFTP_ERETRYABLE);
782f84694489 2003-4-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 139
diff changeset
872 }
782f84694489 2003-4-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 139
diff changeset
873
169
d40f9db52cdf 2003-6-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 168
diff changeset
874 if (listen (parms->data_connection, 1) == -1)
146
782f84694489 2003-4-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 139
diff changeset
875 {
186
13ca1defdc75 2003-6-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 182
diff changeset
876 request->logging_function (gftp_logging_error, request,
146
782f84694489 2003-4-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 139
diff changeset
877 _("Cannot listen on port %d: %s\n"),
782f84694489 2003-4-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 139
diff changeset
878 ntohs (data_addr.sin6_port),
782f84694489 2003-4-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 139
diff changeset
879 g_strerror (errno));
782f84694489 2003-4-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 139
diff changeset
880 gftp_disconnect (request);
782f84694489 2003-4-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 139
diff changeset
881 return (GFTP_ERETRYABLE);
782f84694489 2003-4-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 139
diff changeset
882 }
782f84694489 2003-4-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 139
diff changeset
883
782f84694489 2003-4-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 139
diff changeset
884 if (inet_ntop (AF_INET6, &data_addr.sin6_addr, buf, sizeof (buf)) == NULL)
782f84694489 2003-4-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 139
diff changeset
885 {
186
13ca1defdc75 2003-6-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 182
diff changeset
886 request->logging_function (gftp_logging_error, request,
146
782f84694489 2003-4-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 139
diff changeset
887 _("Cannot get address of local socket: %s\n"),
782f84694489 2003-4-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 139
diff changeset
888 g_strerror (errno));
782f84694489 2003-4-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 139
diff changeset
889 gftp_disconnect (request);
782f84694489 2003-4-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 139
diff changeset
890 return (GFTP_ERETRYABLE);
782f84694489 2003-4-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 139
diff changeset
891 }
782f84694489 2003-4-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 139
diff changeset
892
782f84694489 2003-4-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 139
diff changeset
893 command = g_strdup_printf ("EPRT |2|%s|%d|\n", buf,
782f84694489 2003-4-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 139
diff changeset
894 ntohs (data_addr.sin6_port));
782f84694489 2003-4-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 139
diff changeset
895
292
e5ce6f15290f 2003-10-19 Brian Masney <masneyb@gftp.org>
masneyb
parents: 288
diff changeset
896 resp = rfc959_send_command (request, command, 1);
146
782f84694489 2003-4-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 139
diff changeset
897 g_free (command);
782f84694489 2003-4-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 139
diff changeset
898 if (resp != '2')
782f84694489 2003-4-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 139
diff changeset
899 {
782f84694489 2003-4-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 139
diff changeset
900 gftp_disconnect (request);
782f84694489 2003-4-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 139
diff changeset
901 return (GFTP_ERETRYABLE);
782f84694489 2003-4-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 139
diff changeset
902 }
782f84694489 2003-4-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 139
diff changeset
903 }
782f84694489 2003-4-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 139
diff changeset
904
782f84694489 2003-4-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 139
diff changeset
905 return (0);
782f84694489 2003-4-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 139
diff changeset
906 }
782f84694489 2003-4-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 139
diff changeset
907
782f84694489 2003-4-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 139
diff changeset
908 #endif /* HAVE_IPV6 */
782f84694489 2003-4-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 139
diff changeset
909
782f84694489 2003-4-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 139
diff changeset
910
782f84694489 2003-4-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 139
diff changeset
911 static int
782f84694489 2003-4-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 139
diff changeset
912 rfc959_data_connection_new (gftp_request * request)
782f84694489 2003-4-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 139
diff changeset
913 {
782f84694489 2003-4-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 139
diff changeset
914 g_return_val_if_fail (request != NULL, GFTP_EFATAL);
782f84694489 2003-4-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 139
diff changeset
915 g_return_val_if_fail (request->protonum == GFTP_FTP_NUM, GFTP_EFATAL);
169
d40f9db52cdf 2003-6-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 168
diff changeset
916 g_return_val_if_fail (request->datafd > 0, GFTP_EFATAL);
146
782f84694489 2003-4-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 139
diff changeset
917
782f84694489 2003-4-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 139
diff changeset
918 #ifdef HAVE_IPV6
151
2f15b3000dbc 2003-4-27 Brian Masney <masneyb@gftp.org>
masneyb
parents: 149
diff changeset
919 if (GFTP_GET_AI_FAMILY(request) == AF_INET6)
146
782f84694489 2003-4-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 139
diff changeset
920 return (rfc959_ipv6_data_connection_new (request));
782f84694489 2003-4-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 139
diff changeset
921 else
151
2f15b3000dbc 2003-4-27 Brian Masney <masneyb@gftp.org>
masneyb
parents: 149
diff changeset
922 return (rfc959_ipv4_data_connection_new (request));
2f15b3000dbc 2003-4-27 Brian Masney <masneyb@gftp.org>
masneyb
parents: 149
diff changeset
923 #else
2f15b3000dbc 2003-4-27 Brian Masney <masneyb@gftp.org>
masneyb
parents: 149
diff changeset
924 return (rfc959_ipv4_data_connection_new (request));
146
782f84694489 2003-4-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 139
diff changeset
925 #endif
782f84694489 2003-4-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 139
diff changeset
926 }
782f84694489 2003-4-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 139
diff changeset
927
782f84694489 2003-4-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 139
diff changeset
928
48
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
929 static int
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
930 rfc959_accept_active_connection (gftp_request * request)
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
931 {
325
0fcc6468a0af 2003-12-4 Brian Masney <masneyb@gftp.org>
masneyb
parents: 319
diff changeset
932 int infd, ret;
0fcc6468a0af 2003-12-4 Brian Masney <masneyb@gftp.org>
masneyb
parents: 319
diff changeset
933 intptr_t passive_transfer;
169
d40f9db52cdf 2003-6-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 168
diff changeset
934 rfc959_parms * parms;
146
782f84694489 2003-4-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 139
diff changeset
935 #ifdef HAVE_IPV6
339
542a3e8708f9 2003-12-10 Brian Masney <masneyb@gftp.org>
masneyb
parents: 325
diff changeset
936 struct sockaddr_in6 cli_addr;
146
782f84694489 2003-4-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 139
diff changeset
937 #else
339
542a3e8708f9 2003-12-10 Brian Masney <masneyb@gftp.org>
masneyb
parents: 325
diff changeset
938 struct sockaddr_in cli_addr;
146
782f84694489 2003-4-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 139
diff changeset
939 #endif
195
3fa7b4f4ab78 2003-6-19 Brian Masney <masneyb@gftp.org>
masneyb
parents: 186
diff changeset
940 socklen_t cli_addr_len;
48
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
941
169
d40f9db52cdf 2003-6-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 168
diff changeset
942 parms = request->protocol_data;
d40f9db52cdf 2003-6-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 168
diff changeset
943
84
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
944 g_return_val_if_fail (request != NULL, GFTP_EFATAL);
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
945 g_return_val_if_fail (request->protonum == GFTP_FTP_NUM, GFTP_EFATAL);
169
d40f9db52cdf 2003-6-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 168
diff changeset
946 g_return_val_if_fail (parms->data_connection > 0, GFTP_EFATAL);
122
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 114
diff changeset
947
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 114
diff changeset
948 gftp_lookup_request_option (request, "passive_transfer", &passive_transfer);
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 114
diff changeset
949 g_return_val_if_fail (!passive_transfer, GFTP_EFATAL);
48
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
950
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
951 cli_addr_len = sizeof (cli_addr);
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 48
diff changeset
952
169
d40f9db52cdf 2003-6-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 168
diff changeset
953 if ((ret = gftp_fd_set_sockblocking (request, parms->data_connection, 0)) < 0)
84
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
954 return (ret);
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 48
diff changeset
955
169
d40f9db52cdf 2003-6-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 168
diff changeset
956 if ((infd = accept (parms->data_connection, (struct sockaddr *) &cli_addr,
48
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
957 &cli_addr_len)) == -1)
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
958 {
186
13ca1defdc75 2003-6-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 182
diff changeset
959 request->logging_function (gftp_logging_error, request,
48
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
960 _("Cannot accept connection from server: %s\n"),
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
961 g_strerror (errno));
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
962 gftp_disconnect (request);
84
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
963 return (GFTP_ERETRYABLE);
48
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
964 }
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
965
169
d40f9db52cdf 2003-6-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 168
diff changeset
966 close (parms->data_connection);
48
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
967
169
d40f9db52cdf 2003-6-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 168
diff changeset
968 parms->data_connection = infd;
d40f9db52cdf 2003-6-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 168
diff changeset
969 if ((ret = gftp_fd_set_sockblocking (request, parms->data_connection, 1)) < 0)
84
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
970 return (ret);
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 48
diff changeset
971
48
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
972 return (0);
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
973 }
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
974
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
975
122
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 114
diff changeset
976 static int
254
b0c531678919 2003-8-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 249
diff changeset
977 rfc959_is_ascii_transfer (gftp_request * request, const char *filename)
122
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 114
diff changeset
978 {
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 114
diff changeset
979 gftp_config_list_vars * tmplistvar;
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 114
diff changeset
980 gftp_file_extensions * tempext;
325
0fcc6468a0af 2003-12-4 Brian Masney <masneyb@gftp.org>
masneyb
parents: 319
diff changeset
981 int stlen;
0fcc6468a0af 2003-12-4 Brian Masney <masneyb@gftp.org>
masneyb
parents: 319
diff changeset
982 intptr_t ascii_transfers;
122
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 114
diff changeset
983 GList * templist;
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 114
diff changeset
984
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 114
diff changeset
985 gftp_lookup_global_option ("ext", &tmplistvar);
254
b0c531678919 2003-8-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 249
diff changeset
986 gftp_lookup_request_option (request, "ascii_transfers", &ascii_transfers);
122
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 114
diff changeset
987
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 114
diff changeset
988 stlen = strlen (filename);
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 114
diff changeset
989 for (templist = tmplistvar->list; templist != NULL; templist = templist->next)
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 114
diff changeset
990 {
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 114
diff changeset
991 tempext = templist->data;
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 114
diff changeset
992
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 114
diff changeset
993 if (stlen >= tempext->stlen &&
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 114
diff changeset
994 strcmp (&filename[stlen - tempext->stlen], tempext->ext) == 0)
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 114
diff changeset
995 {
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 114
diff changeset
996 if (toupper (*tempext->ascii_binary == 'A'))
254
b0c531678919 2003-8-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 249
diff changeset
997 ascii_transfers = 1;
b0c531678919 2003-8-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 249
diff changeset
998 else if (toupper (*tempext->ascii_binary == 'B'))
b0c531678919 2003-8-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 249
diff changeset
999 ascii_transfers = 0;
122
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 114
diff changeset
1000 break;
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 114
diff changeset
1001 }
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 114
diff changeset
1002 }
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 114
diff changeset
1003
254
b0c531678919 2003-8-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 249
diff changeset
1004 return (ascii_transfers);
122
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 114
diff changeset
1005 }
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 114
diff changeset
1006
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 114
diff changeset
1007
309
cc2eeb30b793 2003-11-7 Brian Masney <masneyb@gftp.org>
masneyb
parents: 305
diff changeset
1008 static int
122
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 114
diff changeset
1009 rfc959_set_data_type (gftp_request * request, const char *filename)
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 114
diff changeset
1010 {
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 114
diff changeset
1011 rfc959_parms * parms;
309
cc2eeb30b793 2003-11-7 Brian Masney <masneyb@gftp.org>
masneyb
parents: 305
diff changeset
1012 int new_ascii, ret;
122
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 114
diff changeset
1013 char *tempstr;
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 114
diff changeset
1014
309
cc2eeb30b793 2003-11-7 Brian Masney <masneyb@gftp.org>
masneyb
parents: 305
diff changeset
1015 g_return_val_if_fail (request != NULL, GFTP_EFATAL);
cc2eeb30b793 2003-11-7 Brian Masney <masneyb@gftp.org>
masneyb
parents: 305
diff changeset
1016 g_return_val_if_fail (request->protonum == GFTP_FTP_NUM, GFTP_EFATAL);
122
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 114
diff changeset
1017
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 114
diff changeset
1018 parms = request->protocol_data;
254
b0c531678919 2003-8-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 249
diff changeset
1019 new_ascii = rfc959_is_ascii_transfer (request, filename);
122
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 114
diff changeset
1020
169
d40f9db52cdf 2003-6-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 168
diff changeset
1021 if (request->datafd > 0 && new_ascii != parms->is_ascii_transfer)
122
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 114
diff changeset
1022 {
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 114
diff changeset
1023 if (new_ascii)
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 114
diff changeset
1024 {
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 114
diff changeset
1025 tempstr = "TYPE A\r\n";
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 114
diff changeset
1026 parms->is_ascii_transfer = 1;
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 114
diff changeset
1027 }
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 114
diff changeset
1028 else
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 114
diff changeset
1029 {
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 114
diff changeset
1030 tempstr = "TYPE I\r\n";
254
b0c531678919 2003-8-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 249
diff changeset
1031 parms->is_ascii_transfer = 0;
122
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 114
diff changeset
1032 }
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 114
diff changeset
1033
309
cc2eeb30b793 2003-11-7 Brian Masney <masneyb@gftp.org>
masneyb
parents: 305
diff changeset
1034 if ((ret = rfc959_send_command (request, tempstr, 1)) < 0)
cc2eeb30b793 2003-11-7 Brian Masney <masneyb@gftp.org>
masneyb
parents: 305
diff changeset
1035 return (ret);
122
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 114
diff changeset
1036 }
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 114
diff changeset
1037
309
cc2eeb30b793 2003-11-7 Brian Masney <masneyb@gftp.org>
masneyb
parents: 305
diff changeset
1038 return (0);
122
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 114
diff changeset
1039 }
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 114
diff changeset
1040
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 114
diff changeset
1041
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 48
diff changeset
1042 static off_t
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 48
diff changeset
1043 rfc959_get_file (gftp_request * request, const char *filename, int fd,
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1044 off_t startsize)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1045 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1046 char *command, *tempstr, resp;
325
0fcc6468a0af 2003-12-4 Brian Masney <masneyb@gftp.org>
masneyb
parents: 319
diff changeset
1047 int ret;
0fcc6468a0af 2003-12-4 Brian Masney <masneyb@gftp.org>
masneyb
parents: 319
diff changeset
1048 intptr_t passive_transfer;
169
d40f9db52cdf 2003-6-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 168
diff changeset
1049 rfc959_parms * parms;
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1050
84
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
1051 g_return_val_if_fail (request != NULL, GFTP_EFATAL);
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
1052 g_return_val_if_fail (request->protonum == GFTP_FTP_NUM, GFTP_EFATAL);
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
1053 g_return_val_if_fail (filename != NULL, GFTP_EFATAL);
169
d40f9db52cdf 2003-6-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 168
diff changeset
1054 g_return_val_if_fail (request->datafd > 0, GFTP_EFATAL);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1055
169
d40f9db52cdf 2003-6-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 168
diff changeset
1056 parms = request->protocol_data;
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 48
diff changeset
1057 if (fd > 0)
169
d40f9db52cdf 2003-6-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 168
diff changeset
1058 parms->data_connection = fd;
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1059
309
cc2eeb30b793 2003-11-7 Brian Masney <masneyb@gftp.org>
masneyb
parents: 305
diff changeset
1060 if ((ret = rfc959_set_data_type (request, filename)) < 0)
cc2eeb30b793 2003-11-7 Brian Masney <masneyb@gftp.org>
masneyb
parents: 305
diff changeset
1061 return (ret);
122
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 114
diff changeset
1062
169
d40f9db52cdf 2003-6-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 168
diff changeset
1063 if (parms->data_connection < 0 &&
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1064 (ret = rfc959_data_connection_new (request)) < 0)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1065 return (ret);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1066
169
d40f9db52cdf 2003-6-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 168
diff changeset
1067 if ((ret = gftp_fd_set_sockblocking (request, parms->data_connection, 1)) < 0)
84
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
1068 return (ret);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1069
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1070 if (startsize > 0)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1071 {
14
83090328581e * More largefile support. Hopefully all that is left is the configure stuff
masneyb
parents: 7
diff changeset
1072 #if defined (_LARGEFILE_SOURCE)
83090328581e * More largefile support. Hopefully all that is left is the configure stuff
masneyb
parents: 7
diff changeset
1073 command = g_strdup_printf ("REST %lld\r\n", startsize);
83090328581e * More largefile support. Hopefully all that is left is the configure stuff
masneyb
parents: 7
diff changeset
1074 #else
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1075 command = g_strdup_printf ("REST %ld\r\n", startsize);
14
83090328581e * More largefile support. Hopefully all that is left is the configure stuff
masneyb
parents: 7
diff changeset
1076 #endif
292
e5ce6f15290f 2003-10-19 Brian Masney <masneyb@gftp.org>
masneyb
parents: 288
diff changeset
1077 resp = rfc959_send_command (request, command, 1);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1078 g_free (command);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1079
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1080 if (resp != '3')
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1081 {
169
d40f9db52cdf 2003-6-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 168
diff changeset
1082 close (parms->data_connection);
d40f9db52cdf 2003-6-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 168
diff changeset
1083 parms->data_connection = -1;
84
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
1084 return (GFTP_ERETRYABLE);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1085 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1086 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1087
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1088 tempstr = g_strconcat ("RETR ", filename, "\r\n", NULL);
292
e5ce6f15290f 2003-10-19 Brian Masney <masneyb@gftp.org>
masneyb
parents: 288
diff changeset
1089 ret = rfc959_send_command (request, tempstr, 1);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1090 g_free (tempstr);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1091
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1092 if (ret != '1')
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 48
diff changeset
1093 {
169
d40f9db52cdf 2003-6-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 168
diff changeset
1094 close (parms->data_connection);
d40f9db52cdf 2003-6-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 168
diff changeset
1095 parms->data_connection = -1;
84
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
1096 return (GFTP_ERETRYABLE);
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 48
diff changeset
1097 }
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1098
122
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 114
diff changeset
1099 gftp_lookup_request_option (request, "passive_transfer", &passive_transfer);
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 114
diff changeset
1100 if (!passive_transfer &&
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1101 (ret = rfc959_accept_active_connection (request)) < 0)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1102 return (ret);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1103
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1104 if ((tempstr = strrchr (request->last_ftp_response, '(')) == NULL)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1105 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1106 tempstr = request->last_ftp_response + 4;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1107 while (!isdigit ((int) *tempstr) && *tempstr != '\0')
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1108 tempstr++;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1109 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1110 else
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1111 tempstr++;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1112
292
e5ce6f15290f 2003-10-19 Brian Masney <masneyb@gftp.org>
masneyb
parents: 288
diff changeset
1113 parms->sent_retr = 1;
244
afbbc72b73e2 2003-8-3 Brian Masney <masneyb@gftp.org>
masneyb
parents: 227
diff changeset
1114 return (gftp_parse_file_size (tempstr) + startsize);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1115 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1116
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1117
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1118 static int
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 48
diff changeset
1119 rfc959_put_file (gftp_request * request, const char *filename, int fd,
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1120 off_t startsize, off_t totalsize)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1121 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1122 char *command, *tempstr, resp;
325
0fcc6468a0af 2003-12-4 Brian Masney <masneyb@gftp.org>
masneyb
parents: 319
diff changeset
1123 int ret;
0fcc6468a0af 2003-12-4 Brian Masney <masneyb@gftp.org>
masneyb
parents: 319
diff changeset
1124 intptr_t passive_transfer;
169
d40f9db52cdf 2003-6-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 168
diff changeset
1125 rfc959_parms * parms;
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1126
84
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
1127 g_return_val_if_fail (request != NULL, GFTP_EFATAL);
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
1128 g_return_val_if_fail (request->protonum == GFTP_FTP_NUM, GFTP_EFATAL);
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
1129 g_return_val_if_fail (filename != NULL, GFTP_EFATAL);
169
d40f9db52cdf 2003-6-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 168
diff changeset
1130 g_return_val_if_fail (request->datafd > 0, GFTP_EFATAL);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1131
169
d40f9db52cdf 2003-6-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 168
diff changeset
1132 parms = request->protocol_data;
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 48
diff changeset
1133 if (fd > 0)
169
d40f9db52cdf 2003-6-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 168
diff changeset
1134 fd = parms->data_connection;
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1135
309
cc2eeb30b793 2003-11-7 Brian Masney <masneyb@gftp.org>
masneyb
parents: 305
diff changeset
1136 if ((ret = rfc959_set_data_type (request, filename)) < 0)
cc2eeb30b793 2003-11-7 Brian Masney <masneyb@gftp.org>
masneyb
parents: 305
diff changeset
1137 return (ret);
122
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 114
diff changeset
1138
169
d40f9db52cdf 2003-6-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 168
diff changeset
1139 if (parms->data_connection < 0 &&
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1140 (ret = rfc959_data_connection_new (request)) < 0)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1141 return (ret);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1142
169
d40f9db52cdf 2003-6-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 168
diff changeset
1143 if ((ret = gftp_fd_set_sockblocking (request, parms->data_connection, 1)) < 0)
84
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
1144 return (ret);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1145
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1146 if (startsize > 0)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1147 {
14
83090328581e * More largefile support. Hopefully all that is left is the configure stuff
masneyb
parents: 7
diff changeset
1148 #if defined (_LARGEFILE_SOURCE)
83090328581e * More largefile support. Hopefully all that is left is the configure stuff
masneyb
parents: 7
diff changeset
1149 command = g_strdup_printf ("REST %lld\r\n", startsize);
83090328581e * More largefile support. Hopefully all that is left is the configure stuff
masneyb
parents: 7
diff changeset
1150 #else
83090328581e * More largefile support. Hopefully all that is left is the configure stuff
masneyb
parents: 7
diff changeset
1151 command = g_strdup_printf ("REST %ld\r\n", startsize);
83090328581e * More largefile support. Hopefully all that is left is the configure stuff
masneyb
parents: 7
diff changeset
1152 #endif
292
e5ce6f15290f 2003-10-19 Brian Masney <masneyb@gftp.org>
masneyb
parents: 288
diff changeset
1153 resp = rfc959_send_command (request, command, 1);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1154 g_free (command);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1155 if (resp != '3')
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1156 {
169
d40f9db52cdf 2003-6-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 168
diff changeset
1157 close (parms->data_connection);
d40f9db52cdf 2003-6-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 168
diff changeset
1158 parms->data_connection = -1;
84
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
1159 return (GFTP_ERETRYABLE);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1160 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1161 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1162
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1163 tempstr = g_strconcat ("STOR ", filename, "\r\n", NULL);
292
e5ce6f15290f 2003-10-19 Brian Masney <masneyb@gftp.org>
masneyb
parents: 288
diff changeset
1164 ret = rfc959_send_command (request, tempstr, 1);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1165 g_free (tempstr);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1166 if (ret != '1')
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 48
diff changeset
1167 {
169
d40f9db52cdf 2003-6-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 168
diff changeset
1168 close (parms->data_connection);
d40f9db52cdf 2003-6-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 168
diff changeset
1169 parms->data_connection = -1;
84
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
1170 return (GFTP_ERETRYABLE);
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 48
diff changeset
1171 }
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1172
122
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 114
diff changeset
1173 gftp_lookup_request_option (request, "passive_transfer", &passive_transfer);
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 114
diff changeset
1174 if (!passive_transfer &&
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1175 (ret = rfc959_accept_active_connection (request)) < 0)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1176 return (ret);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1177
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1178 return (0);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1179 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1180
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 48
diff changeset
1181
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1182 static long
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1183 rfc959_transfer_file (gftp_request *fromreq, const char *fromfile,
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1184 off_t fromsize, gftp_request *toreq,
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1185 const char *tofile, off_t tosize)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1186 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1187 char *tempstr, *pos, *endpos;
84
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
1188 int ret;
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1189
84
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
1190 g_return_val_if_fail (fromreq != NULL, GFTP_EFATAL);
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
1191 g_return_val_if_fail (fromfile != NULL, GFTP_EFATAL);
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
1192 g_return_val_if_fail (toreq != NULL, GFTP_EFATAL);
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
1193 g_return_val_if_fail (tofile != NULL, GFTP_EFATAL);
169
d40f9db52cdf 2003-6-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 168
diff changeset
1194 g_return_val_if_fail (fromreq->datafd > 0, GFTP_EFATAL);
d40f9db52cdf 2003-6-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 168
diff changeset
1195 g_return_val_if_fail (toreq->datafd > 0, GFTP_EFATAL);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1196
122
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 114
diff changeset
1197 gftp_set_request_option (fromreq, "passive_transfer", GINT_TO_POINTER(1));
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 114
diff changeset
1198 gftp_set_request_option (toreq, "passive_transfer", GINT_TO_POINTER(0));
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1199
292
e5ce6f15290f 2003-10-19 Brian Masney <masneyb@gftp.org>
masneyb
parents: 288
diff changeset
1200 if ((ret = rfc959_send_command (fromreq, "PASV\r\n", 1)) != '2')
84
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
1201 return (ret);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1202
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1203 pos = fromreq->last_ftp_response + 4;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1204 while (!isdigit ((int) *pos) && *pos != '\0')
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1205 pos++;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1206 if (*pos == '\0')
84
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
1207 return (GFTP_EFATAL);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1208
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1209 endpos = pos;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1210 while (*endpos != ')' && *endpos != '\0')
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1211 endpos++;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1212 if (*endpos == ')')
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1213 *endpos = '\0';
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1214
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1215 tempstr = g_strconcat ("PORT ", pos, "\r\n", NULL);
292
e5ce6f15290f 2003-10-19 Brian Masney <masneyb@gftp.org>
masneyb
parents: 288
diff changeset
1216 if ((ret = rfc959_send_command (toreq, tempstr, 1)) != '2')
15
82fabd6ef1c4 FXP fixes (from Tobias Gruetzmacher <tobias@portfolio16.de>)
masneyb
parents: 14
diff changeset
1217 {
82fabd6ef1c4 FXP fixes (from Tobias Gruetzmacher <tobias@portfolio16.de>)
masneyb
parents: 14
diff changeset
1218 g_free (tempstr);
84
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
1219 return (ret);
15
82fabd6ef1c4 FXP fixes (from Tobias Gruetzmacher <tobias@portfolio16.de>)
masneyb
parents: 14
diff changeset
1220 }
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1221 g_free (tempstr);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1222
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1223 tempstr = g_strconcat ("RETR ", fromfile, "\r\n", NULL);
168
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 151
diff changeset
1224 if ((ret = gftp_fd_write (fromreq, tempstr, strlen (tempstr),
169
d40f9db52cdf 2003-6-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 168
diff changeset
1225 fromreq->datafd)) < 0)
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 48
diff changeset
1226 {
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 48
diff changeset
1227 g_free (tempstr);
84
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
1228 return (ret);
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 48
diff changeset
1229 }
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1230 g_free (tempstr);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1231
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1232 tempstr = g_strconcat ("STOR ", tofile, "\r\n", NULL);
168
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 151
diff changeset
1233 if ((ret = gftp_fd_write (toreq, tempstr, strlen (tempstr),
169
d40f9db52cdf 2003-6-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 168
diff changeset
1234 toreq->datafd)) < 0)
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 48
diff changeset
1235 {
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 48
diff changeset
1236 g_free (tempstr);
84
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
1237 return (ret);
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 48
diff changeset
1238 }
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1239 g_free (tempstr);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1240
292
e5ce6f15290f 2003-10-19 Brian Masney <masneyb@gftp.org>
masneyb
parents: 288
diff changeset
1241 if ((ret = rfc959_read_response (fromreq, 1)) < 0)
84
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
1242 return (ret);
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
1243
292
e5ce6f15290f 2003-10-19 Brian Masney <masneyb@gftp.org>
masneyb
parents: 288
diff changeset
1244 if ((ret = rfc959_read_response (toreq, 1)) < 0)
84
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
1245 return (ret);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1246
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1247 return (0);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1248 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1249
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1250
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1251 static int
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1252 rfc959_end_transfer (gftp_request * request)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1253 {
169
d40f9db52cdf 2003-6-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 168
diff changeset
1254 rfc959_parms * parms;
84
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
1255 int ret;
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
1256
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
1257 g_return_val_if_fail (request != NULL, GFTP_EFATAL);
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
1258 g_return_val_if_fail (request->protonum == GFTP_FTP_NUM, GFTP_EFATAL);
169
d40f9db52cdf 2003-6-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 168
diff changeset
1259 g_return_val_if_fail (request->datafd > 0, GFTP_EFATAL);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1260
169
d40f9db52cdf 2003-6-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 168
diff changeset
1261 parms = request->protocol_data;
292
e5ce6f15290f 2003-10-19 Brian Masney <masneyb@gftp.org>
masneyb
parents: 288
diff changeset
1262 parms->sent_retr = 0;
e5ce6f15290f 2003-10-19 Brian Masney <masneyb@gftp.org>
masneyb
parents: 288
diff changeset
1263
169
d40f9db52cdf 2003-6-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 168
diff changeset
1264 if (parms->data_connection > 0)
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1265 {
169
d40f9db52cdf 2003-6-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 168
diff changeset
1266 close (parms->data_connection);
d40f9db52cdf 2003-6-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 168
diff changeset
1267 parms->data_connection = -1;
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1268 }
84
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
1269
292
e5ce6f15290f 2003-10-19 Brian Masney <masneyb@gftp.org>
masneyb
parents: 288
diff changeset
1270 ret = rfc959_read_response (request, 1);
84
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
1271
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
1272 if (ret < 0)
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
1273 return (ret);
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
1274 else if (ret == '2')
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
1275 return (0);
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
1276 else
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
1277 return (GFTP_ERETRYABLE);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1278 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1279
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1280
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1281 static int
40
66c064fd05bc 2002-10-17 Brian Masney <masneyb@gftp.org>
masneyb
parents: 36
diff changeset
1282 rfc959_abort_transfer (gftp_request * request)
66c064fd05bc 2002-10-17 Brian Masney <masneyb@gftp.org>
masneyb
parents: 36
diff changeset
1283 {
169
d40f9db52cdf 2003-6-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 168
diff changeset
1284 rfc959_parms * parms;
40
66c064fd05bc 2002-10-17 Brian Masney <masneyb@gftp.org>
masneyb
parents: 36
diff changeset
1285 int ret;
66c064fd05bc 2002-10-17 Brian Masney <masneyb@gftp.org>
masneyb
parents: 36
diff changeset
1286
84
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
1287 g_return_val_if_fail (request != NULL, GFTP_EFATAL);
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
1288 g_return_val_if_fail (request->protonum == GFTP_FTP_NUM, GFTP_EFATAL);
169
d40f9db52cdf 2003-6-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 168
diff changeset
1289 g_return_val_if_fail (request->datafd > 0, GFTP_EFATAL);
40
66c064fd05bc 2002-10-17 Brian Masney <masneyb@gftp.org>
masneyb
parents: 36
diff changeset
1290
169
d40f9db52cdf 2003-6-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 168
diff changeset
1291 parms = request->protocol_data;
254
b0c531678919 2003-8-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 249
diff changeset
1292
292
e5ce6f15290f 2003-10-19 Brian Masney <masneyb@gftp.org>
masneyb
parents: 288
diff changeset
1293 if ((ret = rfc959_send_command (request, "ABOR\r\n", 0)) < 0)
e5ce6f15290f 2003-10-19 Brian Masney <masneyb@gftp.org>
masneyb
parents: 288
diff changeset
1294 return (ret);
e5ce6f15290f 2003-10-19 Brian Masney <masneyb@gftp.org>
masneyb
parents: 288
diff changeset
1295
169
d40f9db52cdf 2003-6-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 168
diff changeset
1296 if (parms->data_connection > 0)
40
66c064fd05bc 2002-10-17 Brian Masney <masneyb@gftp.org>
masneyb
parents: 36
diff changeset
1297 {
169
d40f9db52cdf 2003-6-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 168
diff changeset
1298 close (parms->data_connection);
d40f9db52cdf 2003-6-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 168
diff changeset
1299 parms->data_connection = -1;
40
66c064fd05bc 2002-10-17 Brian Masney <masneyb@gftp.org>
masneyb
parents: 36
diff changeset
1300 }
66c064fd05bc 2002-10-17 Brian Masney <masneyb@gftp.org>
masneyb
parents: 36
diff changeset
1301
169
d40f9db52cdf 2003-6-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 168
diff changeset
1302 if (request->datafd > 0)
40
66c064fd05bc 2002-10-17 Brian Masney <masneyb@gftp.org>
masneyb
parents: 36
diff changeset
1303 {
292
e5ce6f15290f 2003-10-19 Brian Masney <masneyb@gftp.org>
masneyb
parents: 288
diff changeset
1304 if ((ret = rfc959_read_response (request, 0)) < 0)
40
66c064fd05bc 2002-10-17 Brian Masney <masneyb@gftp.org>
masneyb
parents: 36
diff changeset
1305 gftp_disconnect (request);
66c064fd05bc 2002-10-17 Brian Masney <masneyb@gftp.org>
masneyb
parents: 36
diff changeset
1306 }
292
e5ce6f15290f 2003-10-19 Brian Masney <masneyb@gftp.org>
masneyb
parents: 288
diff changeset
1307
40
66c064fd05bc 2002-10-17 Brian Masney <masneyb@gftp.org>
masneyb
parents: 36
diff changeset
1308 return (0);
66c064fd05bc 2002-10-17 Brian Masney <masneyb@gftp.org>
masneyb
parents: 36
diff changeset
1309 }
66c064fd05bc 2002-10-17 Brian Masney <masneyb@gftp.org>
masneyb
parents: 36
diff changeset
1310
66c064fd05bc 2002-10-17 Brian Masney <masneyb@gftp.org>
masneyb
parents: 36
diff changeset
1311
66c064fd05bc 2002-10-17 Brian Masney <masneyb@gftp.org>
masneyb
parents: 36
diff changeset
1312 static int
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1313 rfc959_list_files (gftp_request * request)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1314 {
325
0fcc6468a0af 2003-12-4 Brian Masney <masneyb@gftp.org>
masneyb
parents: 319
diff changeset
1315 int ret;
0fcc6468a0af 2003-12-4 Brian Masney <masneyb@gftp.org>
masneyb
parents: 319
diff changeset
1316 intptr_t show_hidden_files, resolve_symlinks, passive_transfer;
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1317 char *tempstr, parms[3];
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1318
84
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
1319 g_return_val_if_fail (request != NULL, GFTP_EFATAL);
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
1320 g_return_val_if_fail (request->protonum == GFTP_FTP_NUM, GFTP_EFATAL);
169
d40f9db52cdf 2003-6-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 168
diff changeset
1321 g_return_val_if_fail (request->datafd > 0, GFTP_EFATAL);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1322
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1323 if ((ret = rfc959_data_connection_new (request)) < 0)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1324 return (ret);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1325
122
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 114
diff changeset
1326 gftp_lookup_request_option (request, "show_hidden_files", &show_hidden_files);
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 114
diff changeset
1327 gftp_lookup_request_option (request, "resolve_symlinks", &resolve_symlinks);
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 114
diff changeset
1328 gftp_lookup_request_option (request, "passive_transfer", &passive_transfer);
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 114
diff changeset
1329
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1330 *parms = '\0';
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1331 strcat (parms, show_hidden_files ? "a" : "");
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1332 strcat (parms, resolve_symlinks ? "L" : "");
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1333 tempstr = g_strconcat ("LIST", *parms != '\0' ? " -" : "", parms, "\r\n",
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1334 NULL);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1335
292
e5ce6f15290f 2003-10-19 Brian Masney <masneyb@gftp.org>
masneyb
parents: 288
diff changeset
1336 ret = rfc959_send_command (request, tempstr, 1);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1337 g_free (tempstr);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1338
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1339 if (ret != '1')
84
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
1340 return (GFTP_ERETRYABLE);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1341
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1342 ret = 0;
122
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 114
diff changeset
1343 if (!passive_transfer)
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1344 ret = rfc959_accept_active_connection (request);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1345
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1346 return (ret);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1347 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1348
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1349
122
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 114
diff changeset
1350 static ssize_t
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 114
diff changeset
1351 rfc959_get_next_file_chunk (gftp_request * request, char *buf, size_t size)
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 114
diff changeset
1352 {
301
0386663f9b1f 2003-10-27 Brian Masney <masneyb@gftp.org>
masneyb
parents: 299
diff changeset
1353 ssize_t num_read, ret;
169
d40f9db52cdf 2003-6-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 168
diff changeset
1354 rfc959_parms * parms;
299
6da95954fe41 2003-10-26 Brian Masney <masneyb@gftp.org>
masneyb
parents: 298
diff changeset
1355 int i, j;
122
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 114
diff changeset
1356
169
d40f9db52cdf 2003-6-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 168
diff changeset
1357 parms = request->protocol_data;
299
6da95954fe41 2003-10-26 Brian Masney <masneyb@gftp.org>
masneyb
parents: 298
diff changeset
1358
169
d40f9db52cdf 2003-6-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 168
diff changeset
1359 num_read = gftp_fd_read (request, buf, size, parms->data_connection);
122
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 114
diff changeset
1360 if (num_read < 0)
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 114
diff changeset
1361 return (num_read);
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 114
diff changeset
1362
301
0386663f9b1f 2003-10-27 Brian Masney <masneyb@gftp.org>
masneyb
parents: 299
diff changeset
1363 ret = num_read;
299
6da95954fe41 2003-10-26 Brian Masney <masneyb@gftp.org>
masneyb
parents: 298
diff changeset
1364 if (parms->is_ascii_transfer)
122
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 114
diff changeset
1365 {
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 114
diff changeset
1366 for (i = 0, j = 0; i < num_read; i++)
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 114
diff changeset
1367 {
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 114
diff changeset
1368 if (buf[i] != '\r')
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 114
diff changeset
1369 buf[j++] = buf[i];
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 114
diff changeset
1370 else
301
0386663f9b1f 2003-10-27 Brian Masney <masneyb@gftp.org>
masneyb
parents: 299
diff changeset
1371 ret--;
122
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 114
diff changeset
1372 }
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 114
diff changeset
1373 }
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 114
diff changeset
1374
301
0386663f9b1f 2003-10-27 Brian Masney <masneyb@gftp.org>
masneyb
parents: 299
diff changeset
1375 return (ret);
122
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 114
diff changeset
1376 }
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 114
diff changeset
1377
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 114
diff changeset
1378
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 114
diff changeset
1379 static ssize_t
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 114
diff changeset
1380 rfc959_put_next_file_chunk (gftp_request * request, char *buf, size_t size)
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 114
diff changeset
1381 {
169
d40f9db52cdf 2003-6-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 168
diff changeset
1382 rfc959_parms * parms;
122
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 114
diff changeset
1383 ssize_t num_wrote;
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 114
diff changeset
1384 char *tempstr;
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 114
diff changeset
1385 size_t rsize;
299
6da95954fe41 2003-10-26 Brian Masney <masneyb@gftp.org>
masneyb
parents: 298
diff changeset
1386 int i, j;
122
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 114
diff changeset
1387
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 114
diff changeset
1388 if (size == 0)
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 114
diff changeset
1389 return (0);
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 114
diff changeset
1390
169
d40f9db52cdf 2003-6-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 168
diff changeset
1391 parms = request->protocol_data;
d40f9db52cdf 2003-6-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 168
diff changeset
1392
299
6da95954fe41 2003-10-26 Brian Masney <masneyb@gftp.org>
masneyb
parents: 298
diff changeset
1393 if (parms->is_ascii_transfer)
122
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 114
diff changeset
1394 {
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 114
diff changeset
1395 rsize = 0;
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 114
diff changeset
1396 for (i = 0; i < size; i++)
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 114
diff changeset
1397 {
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 114
diff changeset
1398 rsize++;
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 114
diff changeset
1399 if (i > 0 && buf[i] == '\n' && buf[i - 1] != '\r')
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 114
diff changeset
1400 rsize++;
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 114
diff changeset
1401 }
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 114
diff changeset
1402
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 114
diff changeset
1403 if (rsize != size)
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 114
diff changeset
1404 {
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 114
diff changeset
1405 tempstr = g_malloc (rsize);
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 114
diff changeset
1406
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 114
diff changeset
1407 for (i = 0, j = 0; i < size; i++)
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 114
diff changeset
1408 {
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 114
diff changeset
1409 if (i > 0 && buf[i] == '\n' && buf[i - 1] != '\r')
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 114
diff changeset
1410 tempstr[j++] = '\r';
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 114
diff changeset
1411 tempstr[j++] = buf[i];
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 114
diff changeset
1412 }
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 114
diff changeset
1413 }
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 114
diff changeset
1414 else
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 114
diff changeset
1415 tempstr = buf;
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 114
diff changeset
1416 }
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 114
diff changeset
1417 else
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 114
diff changeset
1418 {
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 114
diff changeset
1419 rsize = size;
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 114
diff changeset
1420 tempstr = buf;
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 114
diff changeset
1421 }
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 114
diff changeset
1422
169
d40f9db52cdf 2003-6-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 168
diff changeset
1423 num_wrote = gftp_fd_write (request, tempstr, rsize, parms->data_connection);
122
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 114
diff changeset
1424
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 114
diff changeset
1425 if (tempstr != buf)
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 114
diff changeset
1426 g_free (tempstr);
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 114
diff changeset
1427
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 114
diff changeset
1428 return (num_wrote);
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 114
diff changeset
1429 }
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 114
diff changeset
1430
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 114
diff changeset
1431
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1432 int
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 48
diff changeset
1433 rfc959_get_next_file (gftp_request * request, gftp_file * fle, int fd)
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1434 {
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 48
diff changeset
1435 rfc959_parms * parms;
249
094e83b55cb1 2003-8-7 Brian Masney <masneyb@gftp.org>
masneyb
parents: 244
diff changeset
1436 char tempstr[1024];
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 48
diff changeset
1437 ssize_t len;
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1438
84
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
1439 g_return_val_if_fail (request != NULL, GFTP_EFATAL);
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
1440 g_return_val_if_fail (request->protonum == GFTP_FTP_NUM, GFTP_EFATAL);
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
1441 g_return_val_if_fail (fle != NULL, GFTP_EFATAL);
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
1442 g_return_val_if_fail (fd > 0, GFTP_EFATAL);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1443
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1444 if (request->last_dir_entry)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1445 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1446 g_free (request->last_dir_entry);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1447 request->last_dir_entry = NULL;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1448 }
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 48
diff changeset
1449
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 48
diff changeset
1450 parms = request->protocol_data;
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 48
diff changeset
1451
169
d40f9db52cdf 2003-6-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 168
diff changeset
1452 if (fd == request->datafd)
d40f9db52cdf 2003-6-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 168
diff changeset
1453 fd = parms->data_connection;
d40f9db52cdf 2003-6-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 168
diff changeset
1454
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1455 do
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1456 {
169
d40f9db52cdf 2003-6-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 168
diff changeset
1457 if ((len = gftp_get_line (request, &parms->dataconn_rbuf,
60
8a9324fb63a4 2002-11-21 Brian Masney <masneyb@gftp.org>
masneyb
parents: 58
diff changeset
1458 tempstr, sizeof (tempstr), fd)) <= 0)
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1459 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1460 gftp_file_destroy (fle);
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 48
diff changeset
1461 return ((int) len);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1462 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1463
91
8c37d73d3f1f 2003-1-21 Brian Masney <masneyb@gftp.org>
masneyb
parents: 84
diff changeset
1464 if (gftp_parse_ls (request, tempstr, fle) != 0)
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1465 {
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 48
diff changeset
1466 if (strncmp (tempstr, "total", strlen ("total")) != 0 &&
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 48
diff changeset
1467 strncmp (tempstr, _("total"), strlen (_("total"))) != 0)
186
13ca1defdc75 2003-6-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 182
diff changeset
1468 request->logging_function (gftp_logging_error, request,
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1469 _("Warning: Cannot parse listing %s\n"),
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1470 tempstr);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1471 gftp_file_destroy (fle);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1472 continue;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1473 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1474 else
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1475 break;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1476 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1477 while (1);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1478
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1479 len = strlen (tempstr);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1480 if (!request->cached)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1481 {
60
8a9324fb63a4 2002-11-21 Brian Masney <masneyb@gftp.org>
masneyb
parents: 58
diff changeset
1482 request->last_dir_entry = g_strdup_printf ("%s\n", tempstr);
168
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 151
diff changeset
1483 request->last_dir_entry_len = strlen (tempstr) + 1;
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1484 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1485 return (len);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1486 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1487
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1488
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1489 static off_t
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1490 rfc959_get_file_size (gftp_request * request, const char *filename)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1491 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1492 char *tempstr;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1493 int ret;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1494
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1495 g_return_val_if_fail (request != NULL, 0);
84
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
1496 g_return_val_if_fail (request->protonum == GFTP_FTP_NUM, GFTP_EFATAL);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1497 g_return_val_if_fail (filename != NULL, 0);
169
d40f9db52cdf 2003-6-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 168
diff changeset
1498 g_return_val_if_fail (request->datafd > 0, 0);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1499
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1500 tempstr = g_strconcat ("SIZE ", filename, "\r\n", NULL);
292
e5ce6f15290f 2003-10-19 Brian Masney <masneyb@gftp.org>
masneyb
parents: 288
diff changeset
1501 ret = rfc959_send_command (request, tempstr, 1);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1502 g_free (tempstr);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1503 if (ret < 0)
84
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
1504 return (ret);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1505
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1506 if (*request->last_ftp_response != '2')
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1507 return (0);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1508 return (strtol (request->last_ftp_response + 4, NULL, 10));
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1509 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1510
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1511
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1512 static int
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1513 rfc959_rmdir (gftp_request * request, const char *directory)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1514 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1515 char *tempstr, ret;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1516
84
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
1517 g_return_val_if_fail (request != NULL, GFTP_EFATAL);
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
1518 g_return_val_if_fail (request->protonum == GFTP_FTP_NUM, GFTP_EFATAL);
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
1519 g_return_val_if_fail (directory != NULL, GFTP_EFATAL);
169
d40f9db52cdf 2003-6-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 168
diff changeset
1520 g_return_val_if_fail (request->datafd > 0, GFTP_EFATAL);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1521
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1522 tempstr = g_strconcat ("RMD ", directory, "\r\n", NULL);
292
e5ce6f15290f 2003-10-19 Brian Masney <masneyb@gftp.org>
masneyb
parents: 288
diff changeset
1523 ret = rfc959_send_command (request, tempstr, 1);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1524 g_free (tempstr);
84
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
1525
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
1526 if (ret < 0)
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
1527 return (ret);
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
1528 else if (ret == '2')
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
1529 return (0);
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
1530 else
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
1531 return (GFTP_ERETRYABLE);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1532 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1533
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1534
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1535 static int
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1536 rfc959_rmfile (gftp_request * request, const char *file)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1537 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1538 char *tempstr, ret;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1539
84
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
1540 g_return_val_if_fail (request != NULL, GFTP_EFATAL);
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
1541 g_return_val_if_fail (request->protonum == GFTP_FTP_NUM, GFTP_EFATAL);
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
1542 g_return_val_if_fail (file != NULL, GFTP_EFATAL);
169
d40f9db52cdf 2003-6-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 168
diff changeset
1543 g_return_val_if_fail (request->datafd > 0, GFTP_EFATAL);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1544
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1545 tempstr = g_strconcat ("DELE ", file, "\r\n", NULL);
292
e5ce6f15290f 2003-10-19 Brian Masney <masneyb@gftp.org>
masneyb
parents: 288
diff changeset
1546 ret = rfc959_send_command (request, tempstr, 1);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1547 g_free (tempstr);
84
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
1548
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
1549 if (ret < 0)
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
1550 return (ret);
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
1551 else if (ret == '2')
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
1552 return (0);
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
1553 else
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
1554 return (GFTP_ERETRYABLE);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1555 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1556
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1557
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1558 static int
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1559 rfc959_mkdir (gftp_request * request, const char *directory)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1560 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1561 char *tempstr, ret;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1562
84
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
1563 g_return_val_if_fail (request != NULL, GFTP_EFATAL);
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
1564 g_return_val_if_fail (request->protonum == GFTP_FTP_NUM, GFTP_EFATAL);
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
1565 g_return_val_if_fail (directory != NULL, GFTP_EFATAL);
169
d40f9db52cdf 2003-6-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 168
diff changeset
1566 g_return_val_if_fail (request->datafd > 0, GFTP_EFATAL);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1567
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1568 tempstr = g_strconcat ("MKD ", directory, "\r\n", NULL);
292
e5ce6f15290f 2003-10-19 Brian Masney <masneyb@gftp.org>
masneyb
parents: 288
diff changeset
1569 ret = rfc959_send_command (request, tempstr, 1);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1570 g_free (tempstr);
84
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
1571
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
1572 if (ret < 0)
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
1573 return (ret);
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
1574 else if (ret == '2')
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
1575 return (0);
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
1576 else
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
1577 return (GFTP_ERETRYABLE);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1578 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1579
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1580
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1581 static int
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1582 rfc959_rename (gftp_request * request, const char *oldname,
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1583 const char *newname)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1584 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1585 char *tempstr, ret;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1586
84
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
1587 g_return_val_if_fail (request != NULL, GFTP_EFATAL);
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
1588 g_return_val_if_fail (request->protonum == GFTP_FTP_NUM, GFTP_EFATAL);
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
1589 g_return_val_if_fail (oldname != NULL, GFTP_EFATAL);
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
1590 g_return_val_if_fail (newname != NULL, GFTP_EFATAL);
169
d40f9db52cdf 2003-6-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 168
diff changeset
1591 g_return_val_if_fail (request->datafd > 0, GFTP_EFATAL);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1592
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1593 tempstr = g_strconcat ("RNFR ", oldname, "\r\n", NULL);
292
e5ce6f15290f 2003-10-19 Brian Masney <masneyb@gftp.org>
masneyb
parents: 288
diff changeset
1594 ret = rfc959_send_command (request, tempstr, 1);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1595 g_free (tempstr);
84
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
1596
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
1597 if (ret < 0)
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
1598 return (ret);
278
3bc63e3dbe12 2003-10-2 Brian Masney <masneyb@gftp.org>
masneyb
parents: 273
diff changeset
1599 else if (ret != '3')
84
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
1600 return (GFTP_ERETRYABLE);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1601
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1602 tempstr = g_strconcat ("RNTO ", newname, "\r\n", NULL);
292
e5ce6f15290f 2003-10-19 Brian Masney <masneyb@gftp.org>
masneyb
parents: 288
diff changeset
1603 ret = rfc959_send_command (request, tempstr, 1);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1604 g_free (tempstr);
84
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
1605
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
1606 if (ret < 0)
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
1607 return (ret);
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
1608 else if (ret == '2')
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
1609 return (0);
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
1610 else
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
1611 return (GFTP_ERETRYABLE);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1612 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1613
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1614
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1615 static int
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1616 rfc959_chmod (gftp_request * request, const char *file, int mode)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1617 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1618 char *tempstr, ret;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1619
84
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
1620 g_return_val_if_fail (request != NULL, GFTP_EFATAL);
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
1621 g_return_val_if_fail (request->protonum == GFTP_FTP_NUM, GFTP_EFATAL);
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
1622 g_return_val_if_fail (file != NULL, GFTP_EFATAL);
169
d40f9db52cdf 2003-6-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 168
diff changeset
1623 g_return_val_if_fail (request->datafd > 0, GFTP_EFATAL);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1624
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1625 tempstr = g_malloc (strlen (file) + (mode / 10) + 16);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1626 sprintf (tempstr, "SITE CHMOD %d %s\r\n", mode, file);
292
e5ce6f15290f 2003-10-19 Brian Masney <masneyb@gftp.org>
masneyb
parents: 288
diff changeset
1627 ret = rfc959_send_command (request, tempstr, 1);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1628 g_free (tempstr);
84
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
1629
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
1630 if (ret < 0)
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
1631 return (ret);
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
1632 else if (ret == '2')
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
1633 return (0);
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
1634 else
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
1635 return (GFTP_ERETRYABLE);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1636 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1637
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1638
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1639 static int
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1640 rfc959_site (gftp_request * request, const char *command)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1641 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1642 char *tempstr, ret;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1643
84
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
1644 g_return_val_if_fail (request != NULL, GFTP_EFATAL);
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
1645 g_return_val_if_fail (request->protonum == GFTP_FTP_NUM, GFTP_EFATAL);
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
1646 g_return_val_if_fail (command != NULL, GFTP_EFATAL);
169
d40f9db52cdf 2003-6-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 168
diff changeset
1647 g_return_val_if_fail (request->datafd > 0, GFTP_EFATAL);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1648
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1649 tempstr = g_strconcat ("SITE ", command, "\r\n", NULL);
292
e5ce6f15290f 2003-10-19 Brian Masney <masneyb@gftp.org>
masneyb
parents: 288
diff changeset
1650 ret = rfc959_send_command (request, tempstr, 1);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1651 g_free (tempstr);
84
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
1652
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
1653 if (ret < 0)
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
1654 return (ret);
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
1655 else if (ret == '2')
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
1656 return (0);
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
1657 else
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
1658 return (GFTP_ERETRYABLE);
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 48
diff changeset
1659 }
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 48
diff changeset
1660
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 48
diff changeset
1661
177
aec4b4541d3a 2003-6-9 Brian Masney <masneyb@gftp.org>
masneyb
parents: 173
diff changeset
1662 static int
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 48
diff changeset
1663 rfc959_set_config_options (gftp_request * request)
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 48
diff changeset
1664 {
122
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 114
diff changeset
1665 char *proxy_config;
177
aec4b4541d3a 2003-6-9 Brian Masney <masneyb@gftp.org>
masneyb
parents: 173
diff changeset
1666 int ret;
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 48
diff changeset
1667
122
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 114
diff changeset
1668 gftp_lookup_request_option (request, "proxy_config", &proxy_config);
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 114
diff changeset
1669 if (strcmp (proxy_config, "http") == 0)
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 48
diff changeset
1670 {
177
aec4b4541d3a 2003-6-9 Brian Masney <masneyb@gftp.org>
masneyb
parents: 173
diff changeset
1671 if ((ret = gftp_protocols[GFTP_HTTP_NUM].init (request)) < 0)
aec4b4541d3a 2003-6-9 Brian Masney <masneyb@gftp.org>
masneyb
parents: 173
diff changeset
1672 return (ret);
173
4c288d05b26a 2003-6-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 169
diff changeset
1673
122
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 114
diff changeset
1674 gftp_set_request_option (request, "proxy_config", "ftp");
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 48
diff changeset
1675 }
177
aec4b4541d3a 2003-6-9 Brian Masney <masneyb@gftp.org>
masneyb
parents: 173
diff changeset
1676
aec4b4541d3a 2003-6-9 Brian Masney <masneyb@gftp.org>
masneyb
parents: 173
diff changeset
1677 return (0);
122
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 114
diff changeset
1678 }
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 48
diff changeset
1679
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 48
diff changeset
1680
122
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 114
diff changeset
1681 void
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 114
diff changeset
1682 rfc959_register_module (void)
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 114
diff changeset
1683 {
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 114
diff changeset
1684 gftp_register_config_vars (config_vars);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1685 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1686
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1687
201
0098dae654a5 2003-6-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 195
diff changeset
1688 void
0098dae654a5 2003-6-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 195
diff changeset
1689 rfc959_request_destroy (gftp_request * request)
0098dae654a5 2003-6-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 195
diff changeset
1690 {
0098dae654a5 2003-6-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 195
diff changeset
1691 rfc959_parms * parms;
0098dae654a5 2003-6-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 195
diff changeset
1692
0098dae654a5 2003-6-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 195
diff changeset
1693 parms = request->protocol_data;
0098dae654a5 2003-6-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 195
diff changeset
1694
0098dae654a5 2003-6-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 195
diff changeset
1695 if (parms->datafd_rbuf != NULL)
0098dae654a5 2003-6-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 195
diff changeset
1696 gftp_free_getline_buffer (&parms->datafd_rbuf);
0098dae654a5 2003-6-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 195
diff changeset
1697
0098dae654a5 2003-6-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 195
diff changeset
1698 if (parms->dataconn_rbuf != NULL)
0098dae654a5 2003-6-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 195
diff changeset
1699 gftp_free_getline_buffer (&parms->dataconn_rbuf);
0098dae654a5 2003-6-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 195
diff changeset
1700 }
0098dae654a5 2003-6-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 195
diff changeset
1701
0098dae654a5 2003-6-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 195
diff changeset
1702
309
cc2eeb30b793 2003-11-7 Brian Masney <masneyb@gftp.org>
masneyb
parents: 305
diff changeset
1703 void
cc2eeb30b793 2003-11-7 Brian Masney <masneyb@gftp.org>
masneyb
parents: 305
diff changeset
1704 rfc959_copy_param_options (gftp_request * dest_request,
cc2eeb30b793 2003-11-7 Brian Masney <masneyb@gftp.org>
masneyb
parents: 305
diff changeset
1705 gftp_request * src_request)
cc2eeb30b793 2003-11-7 Brian Masney <masneyb@gftp.org>
masneyb
parents: 305
diff changeset
1706 {
cc2eeb30b793 2003-11-7 Brian Masney <masneyb@gftp.org>
masneyb
parents: 305
diff changeset
1707 rfc959_parms * dparms, * sparms;
cc2eeb30b793 2003-11-7 Brian Masney <masneyb@gftp.org>
masneyb
parents: 305
diff changeset
1708
cc2eeb30b793 2003-11-7 Brian Masney <masneyb@gftp.org>
masneyb
parents: 305
diff changeset
1709 dparms = dest_request->protocol_data;
cc2eeb30b793 2003-11-7 Brian Masney <masneyb@gftp.org>
masneyb
parents: 305
diff changeset
1710 sparms = src_request->protocol_data;
cc2eeb30b793 2003-11-7 Brian Masney <masneyb@gftp.org>
masneyb
parents: 305
diff changeset
1711
cc2eeb30b793 2003-11-7 Brian Masney <masneyb@gftp.org>
masneyb
parents: 305
diff changeset
1712 dparms->is_ascii_transfer = sparms->is_ascii_transfer;
cc2eeb30b793 2003-11-7 Brian Masney <masneyb@gftp.org>
masneyb
parents: 305
diff changeset
1713 }
cc2eeb30b793 2003-11-7 Brian Masney <masneyb@gftp.org>
masneyb
parents: 305
diff changeset
1714
cc2eeb30b793 2003-11-7 Brian Masney <masneyb@gftp.org>
masneyb
parents: 305
diff changeset
1715
173
4c288d05b26a 2003-6-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 169
diff changeset
1716 int
48
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
1717 rfc959_init (gftp_request * request)
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1718 {
169
d40f9db52cdf 2003-6-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 168
diff changeset
1719 rfc959_parms * parms;
227
a85a097bbb02 2003-7-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 201
diff changeset
1720 struct hostent *hent;
a85a097bbb02 2003-7-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 201
diff changeset
1721 struct utsname unme;
a85a097bbb02 2003-7-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 201
diff changeset
1722 struct passwd *pw;
a85a097bbb02 2003-7-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 201
diff changeset
1723 char *tempstr;
169
d40f9db52cdf 2003-6-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 168
diff changeset
1724
173
4c288d05b26a 2003-6-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 169
diff changeset
1725 g_return_val_if_fail (request != NULL, GFTP_EFATAL);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1726
227
a85a097bbb02 2003-7-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 201
diff changeset
1727 gftp_lookup_global_option ("email", &tempstr);
a85a097bbb02 2003-7-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 201
diff changeset
1728 if (tempstr == NULL || *tempstr == '\0')
a85a097bbb02 2003-7-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 201
diff changeset
1729 {
a85a097bbb02 2003-7-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 201
diff changeset
1730 /* If there is no email address specified, then we'll just use the
a85a097bbb02 2003-7-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 201
diff changeset
1731 currentuser@currenthost */
a85a097bbb02 2003-7-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 201
diff changeset
1732 uname (&unme);
a85a097bbb02 2003-7-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 201
diff changeset
1733 pw = getpwuid (geteuid ());
a85a097bbb02 2003-7-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 201
diff changeset
1734 hent = gethostbyname (unme.nodename);
a85a097bbb02 2003-7-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 201
diff changeset
1735 if (strchr (unme.nodename, '.') == NULL && hent != NULL)
a85a097bbb02 2003-7-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 201
diff changeset
1736 tempstr = g_strconcat (pw->pw_name, "@", hent->h_name, NULL);
a85a097bbb02 2003-7-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 201
diff changeset
1737 else
a85a097bbb02 2003-7-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 201
diff changeset
1738 tempstr = g_strconcat (pw->pw_name, "@", unme.nodename, NULL);
a85a097bbb02 2003-7-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 201
diff changeset
1739 gftp_set_global_option ("email", tempstr);
a85a097bbb02 2003-7-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 201
diff changeset
1740 g_free (tempstr);
a85a097bbb02 2003-7-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 201
diff changeset
1741 }
a85a097bbb02 2003-7-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 201
diff changeset
1742
48
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
1743 request->protonum = GFTP_FTP_NUM;
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
1744 request->init = rfc959_init;
309
cc2eeb30b793 2003-11-7 Brian Masney <masneyb@gftp.org>
masneyb
parents: 305
diff changeset
1745 request->copy_param_options = rfc959_copy_param_options;
201
0098dae654a5 2003-6-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 195
diff changeset
1746 request->destroy = rfc959_request_destroy;
168
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 151
diff changeset
1747 request->read_function = gftp_fd_read;
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 151
diff changeset
1748 request->write_function = gftp_fd_write;
48
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
1749 request->connect = rfc959_connect;
168
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 151
diff changeset
1750 request->post_connect = NULL;
48
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
1751 request->disconnect = rfc959_disconnect;
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
1752 request->get_file = rfc959_get_file;
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
1753 request->put_file = rfc959_put_file;
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
1754 request->transfer_file = rfc959_transfer_file;
122
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 114
diff changeset
1755 request->get_next_file_chunk = rfc959_get_next_file_chunk;
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 114
diff changeset
1756 request->put_next_file_chunk = rfc959_put_next_file_chunk;
48
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
1757 request->end_transfer = rfc959_end_transfer;
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
1758 request->abort_transfer = rfc959_abort_transfer;
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
1759 request->list_files = rfc959_list_files;
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
1760 request->get_next_file = rfc959_get_next_file;
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
1761 request->get_file_size = rfc959_get_file_size;
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
1762 request->chdir = rfc959_chdir;
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
1763 request->rmdir = rfc959_rmdir;
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
1764 request->rmfile = rfc959_rmfile;
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
1765 request->mkdir = rfc959_mkdir;
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
1766 request->rename = rfc959_rename;
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
1767 request->chmod = rfc959_chmod;
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
1768 request->set_file_time = NULL;
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
1769 request->site = rfc959_site;
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
1770 request->parse_url = NULL;
63
41b71c4e5076 2002-11-2333 Brian Masney <masneyb@gftp.org>
masneyb
parents: 60
diff changeset
1771 request->swap_socks = NULL;
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 48
diff changeset
1772 request->set_config_options = rfc959_set_config_options;
48
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
1773 request->url_prefix = "ftp";
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
1774 request->need_hostport = 1;
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
1775 request->need_userpass = 1;
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
1776 request->use_cache = 1;
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
1777 request->always_connected = 0;
169
d40f9db52cdf 2003-6-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 168
diff changeset
1778
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 48
diff changeset
1779 request->protocol_data = g_malloc0 (sizeof (rfc959_parms));
169
d40f9db52cdf 2003-6-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 168
diff changeset
1780 parms = request->protocol_data;
d40f9db52cdf 2003-6-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 168
diff changeset
1781 parms->data_connection = -1;
d40f9db52cdf 2003-6-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 168
diff changeset
1782
177
aec4b4541d3a 2003-6-9 Brian Masney <masneyb@gftp.org>
masneyb
parents: 173
diff changeset
1783 return (gftp_set_config_options (request));
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1784 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1785