annotate lib/rfc959.c @ 484:632036c6e4a4

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