annotate lib/rfc959.c @ 282:e28086437451

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