annotate lib/protocols.c @ 520:e67a52327b24

2004-7-27 Brian Masney <masneyb@gftp.org> * lib/gftp.h lib/local.c lib/protocols.c lib/sshv2.c - changed declaration of gftp_stat_filename() so that the mode of the filename is returned as a parameter instead of the function return value. The mode_t type is unsigned and the error codes could not be reported properly
author masneyb
date Wed, 28 Jul 2004 02:19:00 +0000
parents c6a6e908dbaf
children bccfdbfaac00
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 /* protocols.c - Skeleton functions for the protocols gftp supports */
122
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 107
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: 16
diff changeset
21 static const char cvsid[] = "$Id$";
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
22
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
23 gftp_request *
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
24 gftp_request_new (void)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
25 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
26 gftp_request *request;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
27
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
28 request = g_malloc0 (sizeof (*request));
66
cd3e457cbc85 2002-11-26 Brian Masney <masneyb@gftp.org>
masneyb
parents: 65
diff changeset
29 request->datafd = -1;
cd3e457cbc85 2002-11-26 Brian Masney <masneyb@gftp.org>
masneyb
parents: 65
diff changeset
30 request->cachefd = -1;
122
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 107
diff changeset
31 request->server_type = GFTP_DIRTYPE_OTHER;
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
32 return (request);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
33 }
136
84b3e69807a2 2003-4-18 Brian Masney <masneyb@gftp.org>
masneyb
parents: 125
diff changeset
34
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
35
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
36 void
67
aa971a4bb16f 2002-11-27 Brian Masney <masneyb@gftp.org>
masneyb
parents: 66
diff changeset
37 gftp_request_destroy (gftp_request * request, int free_request)
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
38 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
39 g_return_if_fail (request != NULL);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
40
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
41 gftp_disconnect (request);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
42
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
43 if (request->destroy != NULL)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
44 request->destroy (request);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
45
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
46 if (request->hostname)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
47 g_free (request->hostname);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
48 if (request->username)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
49 g_free (request->username);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
50 if (request->password)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
51 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
52 memset (request->password, 0, strlen (request->password));
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
53 g_free (request->password);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
54 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
55 if (request->account)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
56 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
57 memset (request->account, 0, strlen (request->account));
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
58 g_free (request->account);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
59 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
60 if (request->directory)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
61 g_free (request->directory);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
62 if (request->last_ftp_response)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
63 g_free (request->last_ftp_response);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
64 if (request->protocol_data)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
65 g_free (request->protocol_data);
67
aa971a4bb16f 2002-11-27 Brian Masney <masneyb@gftp.org>
masneyb
parents: 66
diff changeset
66
198
8fea1b1a2ec6 2003-6-22 Brian Masney <masneyb@gftp.org>
masneyb
parents: 191
diff changeset
67 if (request->local_options_vars != NULL)
8fea1b1a2ec6 2003-6-22 Brian Masney <masneyb@gftp.org>
masneyb
parents: 191
diff changeset
68 {
201
0098dae654a5 2003-6-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 199
diff changeset
69 gftp_config_free_options (request->local_options_vars,
0098dae654a5 2003-6-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 199
diff changeset
70 request->local_options_hash,
0098dae654a5 2003-6-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 199
diff changeset
71 request->num_local_options_vars);
198
8fea1b1a2ec6 2003-6-22 Brian Masney <masneyb@gftp.org>
masneyb
parents: 191
diff changeset
72 }
8fea1b1a2ec6 2003-6-22 Brian Masney <masneyb@gftp.org>
masneyb
parents: 191
diff changeset
73
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
74 memset (request, 0, sizeof (*request));
67
aa971a4bb16f 2002-11-27 Brian Masney <masneyb@gftp.org>
masneyb
parents: 66
diff changeset
75
aa971a4bb16f 2002-11-27 Brian Masney <masneyb@gftp.org>
masneyb
parents: 66
diff changeset
76 if (free_request)
aa971a4bb16f 2002-11-27 Brian Masney <masneyb@gftp.org>
masneyb
parents: 66
diff changeset
77 g_free (request);
aa971a4bb16f 2002-11-27 Brian Masney <masneyb@gftp.org>
masneyb
parents: 66
diff changeset
78 else
aa971a4bb16f 2002-11-27 Brian Masney <masneyb@gftp.org>
masneyb
parents: 66
diff changeset
79 {
aa971a4bb16f 2002-11-27 Brian Masney <masneyb@gftp.org>
masneyb
parents: 66
diff changeset
80 request->datafd = -1;
aa971a4bb16f 2002-11-27 Brian Masney <masneyb@gftp.org>
masneyb
parents: 66
diff changeset
81 request->cachefd = -1;
aa971a4bb16f 2002-11-27 Brian Masney <masneyb@gftp.org>
masneyb
parents: 66
diff changeset
82 }
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
83 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
84
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
85
309
cc2eeb30b793 2003-11-7 Brian Masney <masneyb@gftp.org>
masneyb
parents: 303
diff changeset
86 /* This function is called to copy protocol specific data from one request
cc2eeb30b793 2003-11-7 Brian Masney <masneyb@gftp.org>
masneyb
parents: 303
diff changeset
87 structure to another. This is typically called when a file transfer is
cc2eeb30b793 2003-11-7 Brian Masney <masneyb@gftp.org>
masneyb
parents: 303
diff changeset
88 completed, state information can be copied back to the main window */
cc2eeb30b793 2003-11-7 Brian Masney <masneyb@gftp.org>
masneyb
parents: 303
diff changeset
89 void
cc2eeb30b793 2003-11-7 Brian Masney <masneyb@gftp.org>
masneyb
parents: 303
diff changeset
90 gftp_copy_param_options (gftp_request * dest_request,
cc2eeb30b793 2003-11-7 Brian Masney <masneyb@gftp.org>
masneyb
parents: 303
diff changeset
91 gftp_request * src_request)
cc2eeb30b793 2003-11-7 Brian Masney <masneyb@gftp.org>
masneyb
parents: 303
diff changeset
92 {
cc2eeb30b793 2003-11-7 Brian Masney <masneyb@gftp.org>
masneyb
parents: 303
diff changeset
93 g_return_if_fail (dest_request != NULL);
cc2eeb30b793 2003-11-7 Brian Masney <masneyb@gftp.org>
masneyb
parents: 303
diff changeset
94 g_return_if_fail (src_request != NULL);
cc2eeb30b793 2003-11-7 Brian Masney <masneyb@gftp.org>
masneyb
parents: 303
diff changeset
95 g_return_if_fail (dest_request->protonum == src_request->protonum);
cc2eeb30b793 2003-11-7 Brian Masney <masneyb@gftp.org>
masneyb
parents: 303
diff changeset
96
cc2eeb30b793 2003-11-7 Brian Masney <masneyb@gftp.org>
masneyb
parents: 303
diff changeset
97 if (dest_request->copy_param_options)
cc2eeb30b793 2003-11-7 Brian Masney <masneyb@gftp.org>
masneyb
parents: 303
diff changeset
98 dest_request->copy_param_options (dest_request, src_request);
cc2eeb30b793 2003-11-7 Brian Masney <masneyb@gftp.org>
masneyb
parents: 303
diff changeset
99 }
cc2eeb30b793 2003-11-7 Brian Masney <masneyb@gftp.org>
masneyb
parents: 303
diff changeset
100
cc2eeb30b793 2003-11-7 Brian Masney <masneyb@gftp.org>
masneyb
parents: 303
diff changeset
101
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
102 void
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
103 gftp_file_destroy (gftp_file * file)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
104 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
105 g_return_if_fail (file != NULL);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
106
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
107 if (file->file)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
108 g_free (file->file);
349
3fccdc9eb16f 2003-1-4 Brian Masney <masneyb@gftp.org>
masneyb
parents: 325
diff changeset
109 if (file->utf8_file)
3fccdc9eb16f 2003-1-4 Brian Masney <masneyb@gftp.org>
masneyb
parents: 325
diff changeset
110 g_free (file->utf8_file);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
111 if (file->user)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
112 g_free (file->user);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
113 if (file->group)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
114 g_free (file->group);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
115 if (file->destfile)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
116 g_free (file->destfile);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
117 memset (file, 0, sizeof (*file));
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
118 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
119
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
120
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
121 int
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
122 gftp_connect (gftp_request * request)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
123 {
177
aec4b4541d3a 2003-6-9 Brian Masney <masneyb@gftp.org>
masneyb
parents: 173
diff changeset
124 int ret;
aec4b4541d3a 2003-6-9 Brian Masney <masneyb@gftp.org>
masneyb
parents: 173
diff changeset
125
84
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 76
diff changeset
126 g_return_val_if_fail (request != NULL, GFTP_EFATAL);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
127
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
128 if (request->connect == NULL)
84
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 76
diff changeset
129 return (GFTP_EFATAL);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
130
177
aec4b4541d3a 2003-6-9 Brian Masney <masneyb@gftp.org>
masneyb
parents: 173
diff changeset
131 if ((ret = gftp_set_config_options (request)) < 0)
aec4b4541d3a 2003-6-9 Brian Masney <masneyb@gftp.org>
masneyb
parents: 173
diff changeset
132 return (ret);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
133
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
134 return (request->connect (request));
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
135 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
136
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
137
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
138 void
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
139 gftp_disconnect (gftp_request * request)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
140 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
141 g_return_if_fail (request != NULL);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
142
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
143 #if defined (HAVE_GETADDRINFO) && defined (HAVE_GAI_STRERROR)
151
2f15b3000dbc 2003-4-27 Brian Masney <masneyb@gftp.org>
masneyb
parents: 146
diff changeset
144 if (request->free_hostp && request->hostp != NULL)
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
145 freeaddrinfo (request->hostp);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
146 #endif
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
147 request->hostp = NULL;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
148
168
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 151
diff changeset
149 #ifdef USE_SSL
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 151
diff changeset
150 if (request->ssl != NULL)
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 151
diff changeset
151 {
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 151
diff changeset
152 SSL_free (request->ssl);
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 151
diff changeset
153 request->ssl = NULL;
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 151
diff changeset
154 }
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 151
diff changeset
155 #endif
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 151
diff changeset
156
187
a8ec69e39112 2003-6-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 186
diff changeset
157 #if GLIB_MAJOR_VERSION > 1
a8ec69e39112 2003-6-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 186
diff changeset
158 if (request->iconv_initialized)
a8ec69e39112 2003-6-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 186
diff changeset
159 {
a8ec69e39112 2003-6-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 186
diff changeset
160 g_iconv_close (request->iconv);
a8ec69e39112 2003-6-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 186
diff changeset
161 request->iconv_initialized = 0;
a8ec69e39112 2003-6-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 186
diff changeset
162 }
a8ec69e39112 2003-6-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 186
diff changeset
163 #endif
a8ec69e39112 2003-6-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 186
diff changeset
164
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
165 request->cached = 0;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
166 if (request->disconnect == NULL)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
167 return;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
168 request->disconnect (request);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
169 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
170
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
171
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
172 off_t
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
173 gftp_get_file (gftp_request * request, const char *filename, int fd,
244
afbbc72b73e2 2003-8-3 Brian Masney <masneyb@gftp.org>
masneyb
parents: 243
diff changeset
174 off_t startsize)
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
175 {
84
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 76
diff changeset
176 g_return_val_if_fail (request != NULL, GFTP_EFATAL);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
177
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
178 request->cached = 0;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
179 if (request->get_file == NULL)
84
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 76
diff changeset
180 return (GFTP_EFATAL);
244
afbbc72b73e2 2003-8-3 Brian Masney <masneyb@gftp.org>
masneyb
parents: 243
diff changeset
181
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
182 return (request->get_file (request, filename, fd, startsize));
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
183 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
184
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
185
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
186 int
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
187 gftp_put_file (gftp_request * request, const char *filename, int fd,
244
afbbc72b73e2 2003-8-3 Brian Masney <masneyb@gftp.org>
masneyb
parents: 243
diff changeset
188 off_t startsize, off_t totalsize)
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
189 {
84
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 76
diff changeset
190 g_return_val_if_fail (request != NULL, GFTP_EFATAL);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
191
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
192 request->cached = 0;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
193 if (request->put_file == NULL)
84
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 76
diff changeset
194 return (GFTP_EFATAL);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
195 return (request->put_file (request, filename, fd, startsize, totalsize));
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
196 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
197
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
198
261
dbf13a10be13 2003-8-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 260
diff changeset
199 off_t
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
200 gftp_transfer_file (gftp_request * fromreq, const char *fromfile,
244
afbbc72b73e2 2003-8-3 Brian Masney <masneyb@gftp.org>
masneyb
parents: 243
diff changeset
201 int fromfd, off_t fromsize,
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
202 gftp_request * toreq, const char *tofile,
244
afbbc72b73e2 2003-8-3 Brian Masney <masneyb@gftp.org>
masneyb
parents: 243
diff changeset
203 int tofd, off_t tosize)
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
204 {
469
2ad1916dc611 2004-5-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 463
diff changeset
205 /* Needed for systems that size(float) < size(void *) */
2ad1916dc611 2004-5-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 463
diff changeset
206 union { intptr_t i; float f; } maxkbs;
261
dbf13a10be13 2003-8-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 260
diff changeset
207 off_t size;
84
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 76
diff changeset
208 int ret;
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
209
84
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 76
diff changeset
210 g_return_val_if_fail (fromreq != NULL, GFTP_EFATAL);
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 76
diff changeset
211 g_return_val_if_fail (fromfile != NULL, GFTP_EFATAL);
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 76
diff changeset
212 g_return_val_if_fail (toreq != NULL, GFTP_EFATAL);
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 76
diff changeset
213 g_return_val_if_fail (tofile != NULL, GFTP_EFATAL);
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 76
diff changeset
214
469
2ad1916dc611 2004-5-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 463
diff changeset
215 gftp_lookup_request_option (toreq, "maxkbs", &maxkbs.f);
2ad1916dc611 2004-5-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 463
diff changeset
216
2ad1916dc611 2004-5-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 463
diff changeset
217 if (maxkbs.f > 0)
294
4747f621b79b 2003-10-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 291
diff changeset
218 {
4747f621b79b 2003-10-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 291
diff changeset
219 toreq->logging_function (gftp_logging_misc, toreq,
4747f621b79b 2003-10-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 291
diff changeset
220 _("File transfer will be throttled to %.2f KB/s\n"),
469
2ad1916dc611 2004-5-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 463
diff changeset
221 maxkbs.f);
294
4747f621b79b 2003-10-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 291
diff changeset
222 }
4747f621b79b 2003-10-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 291
diff changeset
223
87
6df043359b41 2003-1-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 84
diff changeset
224 if (fromreq->protonum == toreq->protonum &&
84
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 76
diff changeset
225 fromreq->transfer_file != NULL)
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 76
diff changeset
226 return (fromreq->transfer_file (fromreq, fromfile, fromsize, toreq,
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 76
diff changeset
227 tofile, tosize));
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
228
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
229 fromreq->cached = 0;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
230 toreq->cached = 0;
443
6b1e4bd20ae4 2004-3-21 Brian Masney <masneyb@gftp.org>
masneyb
parents: 429
diff changeset
231
6b1e4bd20ae4 2004-3-21 Brian Masney <masneyb@gftp.org>
masneyb
parents: 429
diff changeset
232 get_file:
6b1e4bd20ae4 2004-3-21 Brian Masney <masneyb@gftp.org>
masneyb
parents: 429
diff changeset
233 size = gftp_get_file (fromreq, fromfile, fromfd, tosize);
6b1e4bd20ae4 2004-3-21 Brian Masney <masneyb@gftp.org>
masneyb
parents: 429
diff changeset
234 if (size < 0)
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
235 {
443
6b1e4bd20ae4 2004-3-21 Brian Masney <masneyb@gftp.org>
masneyb
parents: 429
diff changeset
236 if (size == GFTP_ETIMEDOUT)
6b1e4bd20ae4 2004-3-21 Brian Masney <masneyb@gftp.org>
masneyb
parents: 429
diff changeset
237 {
6b1e4bd20ae4 2004-3-21 Brian Masney <masneyb@gftp.org>
masneyb
parents: 429
diff changeset
238 ret = gftp_connect (fromreq);
6b1e4bd20ae4 2004-3-21 Brian Masney <masneyb@gftp.org>
masneyb
parents: 429
diff changeset
239 if (ret < 0)
6b1e4bd20ae4 2004-3-21 Brian Masney <masneyb@gftp.org>
masneyb
parents: 429
diff changeset
240 return (ret);
6b1e4bd20ae4 2004-3-21 Brian Masney <masneyb@gftp.org>
masneyb
parents: 429
diff changeset
241
6b1e4bd20ae4 2004-3-21 Brian Masney <masneyb@gftp.org>
masneyb
parents: 429
diff changeset
242 goto get_file;
6b1e4bd20ae4 2004-3-21 Brian Masney <masneyb@gftp.org>
masneyb
parents: 429
diff changeset
243 }
6b1e4bd20ae4 2004-3-21 Brian Masney <masneyb@gftp.org>
masneyb
parents: 429
diff changeset
244
6b1e4bd20ae4 2004-3-21 Brian Masney <masneyb@gftp.org>
masneyb
parents: 429
diff changeset
245 return (size);
6b1e4bd20ae4 2004-3-21 Brian Masney <masneyb@gftp.org>
masneyb
parents: 429
diff changeset
246 }
6b1e4bd20ae4 2004-3-21 Brian Masney <masneyb@gftp.org>
masneyb
parents: 429
diff changeset
247
6b1e4bd20ae4 2004-3-21 Brian Masney <masneyb@gftp.org>
masneyb
parents: 429
diff changeset
248 put_file:
6b1e4bd20ae4 2004-3-21 Brian Masney <masneyb@gftp.org>
masneyb
parents: 429
diff changeset
249 ret = gftp_put_file (toreq, tofile, tofd, tosize, size);
6b1e4bd20ae4 2004-3-21 Brian Masney <masneyb@gftp.org>
masneyb
parents: 429
diff changeset
250 if (ret != 0)
6b1e4bd20ae4 2004-3-21 Brian Masney <masneyb@gftp.org>
masneyb
parents: 429
diff changeset
251 {
6b1e4bd20ae4 2004-3-21 Brian Masney <masneyb@gftp.org>
masneyb
parents: 429
diff changeset
252 if (size == GFTP_ETIMEDOUT)
6b1e4bd20ae4 2004-3-21 Brian Masney <masneyb@gftp.org>
masneyb
parents: 429
diff changeset
253 {
6b1e4bd20ae4 2004-3-21 Brian Masney <masneyb@gftp.org>
masneyb
parents: 429
diff changeset
254 ret = gftp_connect (fromreq);
6b1e4bd20ae4 2004-3-21 Brian Masney <masneyb@gftp.org>
masneyb
parents: 429
diff changeset
255 if (ret < 0)
6b1e4bd20ae4 2004-3-21 Brian Masney <masneyb@gftp.org>
masneyb
parents: 429
diff changeset
256 return (ret);
6b1e4bd20ae4 2004-3-21 Brian Masney <masneyb@gftp.org>
masneyb
parents: 429
diff changeset
257
6b1e4bd20ae4 2004-3-21 Brian Masney <masneyb@gftp.org>
masneyb
parents: 429
diff changeset
258 goto put_file;
6b1e4bd20ae4 2004-3-21 Brian Masney <masneyb@gftp.org>
masneyb
parents: 429
diff changeset
259 }
6b1e4bd20ae4 2004-3-21 Brian Masney <masneyb@gftp.org>
masneyb
parents: 429
diff changeset
260
40
66c064fd05bc 2002-10-17 Brian Masney <masneyb@gftp.org>
masneyb
parents: 39
diff changeset
261 if (gftp_abort_transfer (fromreq) != 0)
66c064fd05bc 2002-10-17 Brian Masney <masneyb@gftp.org>
masneyb
parents: 39
diff changeset
262 gftp_end_transfer (fromreq);
66c064fd05bc 2002-10-17 Brian Masney <masneyb@gftp.org>
masneyb
parents: 39
diff changeset
263
84
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 76
diff changeset
264 return (ret);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
265 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
266
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
267 return (size);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
268 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
269
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
270
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
271 ssize_t
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
272 gftp_get_next_file_chunk (gftp_request * request, char *buf, size_t size)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
273 {
84
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 76
diff changeset
274 g_return_val_if_fail (request != NULL, GFTP_EFATAL);
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 76
diff changeset
275 g_return_val_if_fail (buf != NULL, GFTP_EFATAL);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
276
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
277 if (request->get_next_file_chunk != NULL)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
278 return (request->get_next_file_chunk (request, buf, size));
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
279
168
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 151
diff changeset
280 return (request->read_function (request, buf, size, request->datafd));
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
281 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
282
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
283
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
284 ssize_t
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
285 gftp_put_next_file_chunk (gftp_request * request, char *buf, size_t size)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
286 {
84
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 76
diff changeset
287 g_return_val_if_fail (request != NULL, GFTP_EFATAL);
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 76
diff changeset
288 g_return_val_if_fail (buf != NULL, GFTP_EFATAL);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
289
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
290 if (request->put_next_file_chunk != NULL)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
291 return (request->put_next_file_chunk (request, buf, size));
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
292
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
293 if (size == 0)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
294 return (0);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
295
168
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 151
diff changeset
296 return (request->write_function (request, buf, size, request->datafd));
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
297 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
298
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
299
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
300 int
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
301 gftp_end_transfer (gftp_request * request)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
302 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
303 int ret;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
304
84
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 76
diff changeset
305 g_return_val_if_fail (request != NULL, GFTP_EFATAL);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
306
40
66c064fd05bc 2002-10-17 Brian Masney <masneyb@gftp.org>
masneyb
parents: 39
diff changeset
307 if (!request->cached &&
66c064fd05bc 2002-10-17 Brian Masney <masneyb@gftp.org>
masneyb
parents: 39
diff changeset
308 request->end_transfer != NULL)
66c064fd05bc 2002-10-17 Brian Masney <masneyb@gftp.org>
masneyb
parents: 39
diff changeset
309 ret = request->end_transfer (request);
66c064fd05bc 2002-10-17 Brian Masney <masneyb@gftp.org>
masneyb
parents: 39
diff changeset
310 else
66c064fd05bc 2002-10-17 Brian Masney <masneyb@gftp.org>
masneyb
parents: 39
diff changeset
311 ret = 0;
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
312
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
313 if (request->cachefd > 0)
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
314 {
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
315 close (request->cachefd);
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
316 request->cachefd = -1;
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
317 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
318
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
319 if (request->last_dir_entry)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
320 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
321 g_free (request->last_dir_entry);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
322 request->last_dir_entry = NULL;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
323 request->last_dir_entry_len = 0;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
324 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
325
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
326 return (ret);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
327 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
328
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
329
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
330 int
40
66c064fd05bc 2002-10-17 Brian Masney <masneyb@gftp.org>
masneyb
parents: 39
diff changeset
331 gftp_abort_transfer (gftp_request * request)
66c064fd05bc 2002-10-17 Brian Masney <masneyb@gftp.org>
masneyb
parents: 39
diff changeset
332 {
84
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 76
diff changeset
333 g_return_val_if_fail (request != NULL, GFTP_EFATAL);
40
66c064fd05bc 2002-10-17 Brian Masney <masneyb@gftp.org>
masneyb
parents: 39
diff changeset
334
66c064fd05bc 2002-10-17 Brian Masney <masneyb@gftp.org>
masneyb
parents: 39
diff changeset
335 if (request->abort_transfer == NULL)
84
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 76
diff changeset
336 return (GFTP_EFATAL);
40
66c064fd05bc 2002-10-17 Brian Masney <masneyb@gftp.org>
masneyb
parents: 39
diff changeset
337
66c064fd05bc 2002-10-17 Brian Masney <masneyb@gftp.org>
masneyb
parents: 39
diff changeset
338 return (request->abort_transfer (request));
66c064fd05bc 2002-10-17 Brian Masney <masneyb@gftp.org>
masneyb
parents: 39
diff changeset
339 }
66c064fd05bc 2002-10-17 Brian Masney <masneyb@gftp.org>
masneyb
parents: 39
diff changeset
340
66c064fd05bc 2002-10-17 Brian Masney <masneyb@gftp.org>
masneyb
parents: 39
diff changeset
341
520
e67a52327b24 2004-7-27 Brian Masney <masneyb@gftp.org>
masneyb
parents: 518
diff changeset
342 int
e67a52327b24 2004-7-27 Brian Masney <masneyb@gftp.org>
masneyb
parents: 518
diff changeset
343 gftp_stat_filename (gftp_request * request, const char *filename, mode_t * mode)
500
ba50a7085d93 2004-7-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 499
diff changeset
344 {
ba50a7085d93 2004-7-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 499
diff changeset
345 g_return_val_if_fail (request != NULL, GFTP_EFATAL);
520
e67a52327b24 2004-7-27 Brian Masney <masneyb@gftp.org>
masneyb
parents: 518
diff changeset
346 g_return_val_if_fail (filename != NULL, GFTP_EFATAL);
500
ba50a7085d93 2004-7-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 499
diff changeset
347
ba50a7085d93 2004-7-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 499
diff changeset
348 if (request->stat_filename != NULL)
520
e67a52327b24 2004-7-27 Brian Masney <masneyb@gftp.org>
masneyb
parents: 518
diff changeset
349 return (request->stat_filename (request, filename, mode));
500
ba50a7085d93 2004-7-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 499
diff changeset
350 else
520
e67a52327b24 2004-7-27 Brian Masney <masneyb@gftp.org>
masneyb
parents: 518
diff changeset
351 return (0);
500
ba50a7085d93 2004-7-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 499
diff changeset
352 }
ba50a7085d93 2004-7-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 499
diff changeset
353
ba50a7085d93 2004-7-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 499
diff changeset
354
40
66c064fd05bc 2002-10-17 Brian Masney <masneyb@gftp.org>
masneyb
parents: 39
diff changeset
355 int
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
356 gftp_list_files (gftp_request * request)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
357 {
473
45fb9dc47a2e 2004-5-26 Brian Masney <masneyb@gftp.org>
masneyb
parents: 469
diff changeset
358 char *remote_lc_time, *locret;
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
359 int fd;
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
360
84
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 76
diff changeset
361 g_return_val_if_fail (request != NULL, GFTP_EFATAL);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
362
473
45fb9dc47a2e 2004-5-26 Brian Masney <masneyb@gftp.org>
masneyb
parents: 469
diff changeset
363 gftp_lookup_request_option (request, "remote_lc_time", &remote_lc_time);
45fb9dc47a2e 2004-5-26 Brian Masney <masneyb@gftp.org>
masneyb
parents: 469
diff changeset
364 if (remote_lc_time != NULL && *remote_lc_time != '\0')
45fb9dc47a2e 2004-5-26 Brian Masney <masneyb@gftp.org>
masneyb
parents: 469
diff changeset
365 locret = setlocale (LC_TIME, remote_lc_time);
45fb9dc47a2e 2004-5-26 Brian Masney <masneyb@gftp.org>
masneyb
parents: 469
diff changeset
366 else
45fb9dc47a2e 2004-5-26 Brian Masney <masneyb@gftp.org>
masneyb
parents: 469
diff changeset
367 locret = setlocale (LC_TIME, NULL);
45fb9dc47a2e 2004-5-26 Brian Masney <masneyb@gftp.org>
masneyb
parents: 469
diff changeset
368
45fb9dc47a2e 2004-5-26 Brian Masney <masneyb@gftp.org>
masneyb
parents: 469
diff changeset
369 if (locret == NULL)
45fb9dc47a2e 2004-5-26 Brian Masney <masneyb@gftp.org>
masneyb
parents: 469
diff changeset
370 {
45fb9dc47a2e 2004-5-26 Brian Masney <masneyb@gftp.org>
masneyb
parents: 469
diff changeset
371 locret = setlocale (LC_TIME, NULL);
45fb9dc47a2e 2004-5-26 Brian Masney <masneyb@gftp.org>
masneyb
parents: 469
diff changeset
372 request->logging_function (gftp_logging_misc, request,
45fb9dc47a2e 2004-5-26 Brian Masney <masneyb@gftp.org>
masneyb
parents: 469
diff changeset
373 _("Error setting LC_TIME to '%s'. Falling back to '%s'\n"),
45fb9dc47a2e 2004-5-26 Brian Masney <masneyb@gftp.org>
masneyb
parents: 469
diff changeset
374 remote_lc_time, locret);
45fb9dc47a2e 2004-5-26 Brian Masney <masneyb@gftp.org>
masneyb
parents: 469
diff changeset
375 }
45fb9dc47a2e 2004-5-26 Brian Masney <masneyb@gftp.org>
masneyb
parents: 469
diff changeset
376
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
377 request->cached = 0;
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
378 if (request->use_cache && (fd = gftp_find_cache_entry (request)) > 0)
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
379 {
186
13ca1defdc75 2003-6-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 185
diff changeset
380 request->logging_function (gftp_logging_misc, request,
473
45fb9dc47a2e 2004-5-26 Brian Masney <masneyb@gftp.org>
masneyb
parents: 469
diff changeset
381 _("Loading directory listing %s from cache (LC_TIME=%s)\n"),
45fb9dc47a2e 2004-5-26 Brian Masney <masneyb@gftp.org>
masneyb
parents: 469
diff changeset
382 request->directory, locret);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
383
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
384 request->cachefd = fd;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
385 request->cached = 1;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
386 return (0);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
387 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
388 else if (request->use_cache)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
389 {
473
45fb9dc47a2e 2004-5-26 Brian Masney <masneyb@gftp.org>
masneyb
parents: 469
diff changeset
390 request->logging_function (gftp_logging_misc, request,
45fb9dc47a2e 2004-5-26 Brian Masney <masneyb@gftp.org>
masneyb
parents: 469
diff changeset
391 _("Loading directory listing %s from server (LC_TIME=%s)\n"),
45fb9dc47a2e 2004-5-26 Brian Masney <masneyb@gftp.org>
masneyb
parents: 469
diff changeset
392 request->directory, locret);
45fb9dc47a2e 2004-5-26 Brian Masney <masneyb@gftp.org>
masneyb
parents: 469
diff changeset
393
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
394 request->cachefd = gftp_new_cache_entry (request);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
395 request->cached = 0;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
396 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
397
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
398 if (request->list_files == NULL)
84
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 76
diff changeset
399 return (GFTP_EFATAL);
473
45fb9dc47a2e 2004-5-26 Brian Masney <masneyb@gftp.org>
masneyb
parents: 469
diff changeset
400
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
401 return (request->list_files (request));
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
402 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
403
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
404
184
65eb40fb4f03 2003-6-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 182
diff changeset
405 #if GLIB_MAJOR_VERSION > 1
291
265244924868 2003-10-19 Brian Masney <masneyb@gftp.org>
masneyb
parents: 281
diff changeset
406
184
65eb40fb4f03 2003-6-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 182
diff changeset
407 static char *
423
4cee2498761d 2004-3-15 Brian Masney <masneyb@gftp.org>
masneyb
parents: 422
diff changeset
408 _gftp_get_next_charset (char **curpos)
184
65eb40fb4f03 2003-6-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 182
diff changeset
409 {
65eb40fb4f03 2003-6-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 182
diff changeset
410 char *ret, *endpos;
65eb40fb4f03 2003-6-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 182
diff changeset
411
65eb40fb4f03 2003-6-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 182
diff changeset
412 if (**curpos == '\0')
65eb40fb4f03 2003-6-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 182
diff changeset
413 return (NULL);
65eb40fb4f03 2003-6-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 182
diff changeset
414
65eb40fb4f03 2003-6-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 182
diff changeset
415 ret = *curpos;
185
cc94bd62d290 2003-6-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 184
diff changeset
416 if ((endpos = strchr (*curpos, ',')) == NULL)
184
65eb40fb4f03 2003-6-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 182
diff changeset
417 *curpos += strlen (*curpos);
65eb40fb4f03 2003-6-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 182
diff changeset
418 else
65eb40fb4f03 2003-6-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 182
diff changeset
419 {
65eb40fb4f03 2003-6-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 182
diff changeset
420 *endpos = '\0';
423
4cee2498761d 2004-3-15 Brian Masney <masneyb@gftp.org>
masneyb
parents: 422
diff changeset
421 *curpos = endpos + 1;
184
65eb40fb4f03 2003-6-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 182
diff changeset
422 }
65eb40fb4f03 2003-6-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 182
diff changeset
423
65eb40fb4f03 2003-6-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 182
diff changeset
424 return (ret);
65eb40fb4f03 2003-6-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 182
diff changeset
425 }
65eb40fb4f03 2003-6-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 182
diff changeset
426
65eb40fb4f03 2003-6-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 182
diff changeset
427
186
13ca1defdc75 2003-6-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 185
diff changeset
428 char *
291
265244924868 2003-10-19 Brian Masney <masneyb@gftp.org>
masneyb
parents: 281
diff changeset
429 gftp_string_to_utf8 (gftp_request * request, const char *str)
184
65eb40fb4f03 2003-6-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 182
diff changeset
430 {
423
4cee2498761d 2004-3-15 Brian Masney <masneyb@gftp.org>
masneyb
parents: 422
diff changeset
431 char *ret, *remote_charsets, *stpos, *cur_charset, *tempstr;
184
65eb40fb4f03 2003-6-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 182
diff changeset
432 gsize bread, bwrite;
65eb40fb4f03 2003-6-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 182
diff changeset
433 GError * error;
65eb40fb4f03 2003-6-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 182
diff changeset
434
188
836822c2d4e7 2003-6-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 187
diff changeset
435 if (request == NULL)
836822c2d4e7 2003-6-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 187
diff changeset
436 return (NULL);
836822c2d4e7 2003-6-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 187
diff changeset
437
184
65eb40fb4f03 2003-6-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 182
diff changeset
438 if (request->iconv_initialized)
65eb40fb4f03 2003-6-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 182
diff changeset
439 return (g_convert_with_iconv (str, -1, request->iconv, &bread, &bwrite,
65eb40fb4f03 2003-6-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 182
diff changeset
440 &error));
291
265244924868 2003-10-19 Brian Masney <masneyb@gftp.org>
masneyb
parents: 281
diff changeset
441 else if (g_utf8_validate (str, -1, NULL))
265244924868 2003-10-19 Brian Masney <masneyb@gftp.org>
masneyb
parents: 281
diff changeset
442 return (NULL);
184
65eb40fb4f03 2003-6-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 182
diff changeset
443
423
4cee2498761d 2004-3-15 Brian Masney <masneyb@gftp.org>
masneyb
parents: 422
diff changeset
444 gftp_lookup_request_option (request, "remote_charsets", &tempstr);
4cee2498761d 2004-3-15 Brian Masney <masneyb@gftp.org>
masneyb
parents: 422
diff changeset
445 if (*tempstr == '\0')
184
65eb40fb4f03 2003-6-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 182
diff changeset
446 {
65eb40fb4f03 2003-6-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 182
diff changeset
447 error = NULL;
65eb40fb4f03 2003-6-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 182
diff changeset
448 if ((ret = g_locale_to_utf8 (str, -1, &bread, &bwrite, &error)) != NULL)
65eb40fb4f03 2003-6-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 182
diff changeset
449 return (ret);
65eb40fb4f03 2003-6-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 182
diff changeset
450
65eb40fb4f03 2003-6-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 182
diff changeset
451 return (NULL);
65eb40fb4f03 2003-6-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 182
diff changeset
452 }
65eb40fb4f03 2003-6-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 182
diff changeset
453
423
4cee2498761d 2004-3-15 Brian Masney <masneyb@gftp.org>
masneyb
parents: 422
diff changeset
454 remote_charsets = g_strdup (tempstr);
184
65eb40fb4f03 2003-6-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 182
diff changeset
455 ret = NULL;
65eb40fb4f03 2003-6-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 182
diff changeset
456 stpos = remote_charsets;
423
4cee2498761d 2004-3-15 Brian Masney <masneyb@gftp.org>
masneyb
parents: 422
diff changeset
457 while ((cur_charset = _gftp_get_next_charset (&stpos)) != NULL)
184
65eb40fb4f03 2003-6-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 182
diff changeset
458 {
65eb40fb4f03 2003-6-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 182
diff changeset
459 if ((request->iconv = g_iconv_open ("UTF-8", cur_charset)) == (GIConv) -1)
65eb40fb4f03 2003-6-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 182
diff changeset
460 continue;
65eb40fb4f03 2003-6-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 182
diff changeset
461
65eb40fb4f03 2003-6-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 182
diff changeset
462 error = NULL;
65eb40fb4f03 2003-6-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 182
diff changeset
463 if ((ret = g_convert_with_iconv (str, -1, request->iconv, &bread, &bwrite,
65eb40fb4f03 2003-6-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 182
diff changeset
464 &error)) == NULL)
65eb40fb4f03 2003-6-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 182
diff changeset
465 {
65eb40fb4f03 2003-6-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 182
diff changeset
466 g_iconv_close (request->iconv);
65eb40fb4f03 2003-6-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 182
diff changeset
467 request->iconv = NULL;
65eb40fb4f03 2003-6-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 182
diff changeset
468 continue;
65eb40fb4f03 2003-6-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 182
diff changeset
469 }
65eb40fb4f03 2003-6-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 182
diff changeset
470 else
65eb40fb4f03 2003-6-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 182
diff changeset
471 {
65eb40fb4f03 2003-6-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 182
diff changeset
472 request->iconv_initialized = 1;
65eb40fb4f03 2003-6-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 182
diff changeset
473 break;
65eb40fb4f03 2003-6-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 182
diff changeset
474 }
65eb40fb4f03 2003-6-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 182
diff changeset
475 }
65eb40fb4f03 2003-6-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 182
diff changeset
476
423
4cee2498761d 2004-3-15 Brian Masney <masneyb@gftp.org>
masneyb
parents: 422
diff changeset
477 g_free (remote_charsets);
4cee2498761d 2004-3-15 Brian Masney <masneyb@gftp.org>
masneyb
parents: 422
diff changeset
478
184
65eb40fb4f03 2003-6-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 182
diff changeset
479 return (ret);
65eb40fb4f03 2003-6-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 182
diff changeset
480 }
291
265244924868 2003-10-19 Brian Masney <masneyb@gftp.org>
masneyb
parents: 281
diff changeset
481
265244924868 2003-10-19 Brian Masney <masneyb@gftp.org>
masneyb
parents: 281
diff changeset
482
265244924868 2003-10-19 Brian Masney <masneyb@gftp.org>
masneyb
parents: 281
diff changeset
483 char *
265244924868 2003-10-19 Brian Masney <masneyb@gftp.org>
masneyb
parents: 281
diff changeset
484 gftp_string_from_utf8 (gftp_request * request, const char *str)
265244924868 2003-10-19 Brian Masney <masneyb@gftp.org>
masneyb
parents: 281
diff changeset
485 {
423
4cee2498761d 2004-3-15 Brian Masney <masneyb@gftp.org>
masneyb
parents: 422
diff changeset
486 char *ret, *remote_charsets, *stpos, *cur_charset, *tempstr;
291
265244924868 2003-10-19 Brian Masney <masneyb@gftp.org>
masneyb
parents: 281
diff changeset
487 gsize bread, bwrite;
265244924868 2003-10-19 Brian Masney <masneyb@gftp.org>
masneyb
parents: 281
diff changeset
488 GError * error;
265244924868 2003-10-19 Brian Masney <masneyb@gftp.org>
masneyb
parents: 281
diff changeset
489
265244924868 2003-10-19 Brian Masney <masneyb@gftp.org>
masneyb
parents: 281
diff changeset
490 if (request == NULL)
265244924868 2003-10-19 Brian Masney <masneyb@gftp.org>
masneyb
parents: 281
diff changeset
491 return (NULL);
265244924868 2003-10-19 Brian Masney <masneyb@gftp.org>
masneyb
parents: 281
diff changeset
492
265244924868 2003-10-19 Brian Masney <masneyb@gftp.org>
masneyb
parents: 281
diff changeset
493 if (request->iconv_initialized)
265244924868 2003-10-19 Brian Masney <masneyb@gftp.org>
masneyb
parents: 281
diff changeset
494 return (g_convert_with_iconv (str, -1, request->iconv, &bread, &bwrite,
265244924868 2003-10-19 Brian Masney <masneyb@gftp.org>
masneyb
parents: 281
diff changeset
495 &error));
265244924868 2003-10-19 Brian Masney <masneyb@gftp.org>
masneyb
parents: 281
diff changeset
496 else if (g_utf8_validate (str, -1, NULL))
265244924868 2003-10-19 Brian Masney <masneyb@gftp.org>
masneyb
parents: 281
diff changeset
497 return (NULL);
265244924868 2003-10-19 Brian Masney <masneyb@gftp.org>
masneyb
parents: 281
diff changeset
498
423
4cee2498761d 2004-3-15 Brian Masney <masneyb@gftp.org>
masneyb
parents: 422
diff changeset
499 gftp_lookup_request_option (request, "remote_charsets", &tempstr);
4cee2498761d 2004-3-15 Brian Masney <masneyb@gftp.org>
masneyb
parents: 422
diff changeset
500 if (*tempstr == '\0')
291
265244924868 2003-10-19 Brian Masney <masneyb@gftp.org>
masneyb
parents: 281
diff changeset
501 {
265244924868 2003-10-19 Brian Masney <masneyb@gftp.org>
masneyb
parents: 281
diff changeset
502 error = NULL;
265244924868 2003-10-19 Brian Masney <masneyb@gftp.org>
masneyb
parents: 281
diff changeset
503 if ((ret = g_locale_from_utf8 (str, -1, &bread, &bwrite, &error)) != NULL)
265244924868 2003-10-19 Brian Masney <masneyb@gftp.org>
masneyb
parents: 281
diff changeset
504 return (ret);
265244924868 2003-10-19 Brian Masney <masneyb@gftp.org>
masneyb
parents: 281
diff changeset
505
265244924868 2003-10-19 Brian Masney <masneyb@gftp.org>
masneyb
parents: 281
diff changeset
506 return (NULL);
265244924868 2003-10-19 Brian Masney <masneyb@gftp.org>
masneyb
parents: 281
diff changeset
507 }
265244924868 2003-10-19 Brian Masney <masneyb@gftp.org>
masneyb
parents: 281
diff changeset
508
423
4cee2498761d 2004-3-15 Brian Masney <masneyb@gftp.org>
masneyb
parents: 422
diff changeset
509 remote_charsets = g_strdup (tempstr);
291
265244924868 2003-10-19 Brian Masney <masneyb@gftp.org>
masneyb
parents: 281
diff changeset
510 ret = NULL;
265244924868 2003-10-19 Brian Masney <masneyb@gftp.org>
masneyb
parents: 281
diff changeset
511 stpos = remote_charsets;
423
4cee2498761d 2004-3-15 Brian Masney <masneyb@gftp.org>
masneyb
parents: 422
diff changeset
512 while ((cur_charset = _gftp_get_next_charset (&stpos)) != NULL)
291
265244924868 2003-10-19 Brian Masney <masneyb@gftp.org>
masneyb
parents: 281
diff changeset
513 {
265244924868 2003-10-19 Brian Masney <masneyb@gftp.org>
masneyb
parents: 281
diff changeset
514 if ((request->iconv = g_iconv_open (cur_charset, "UTF-8")) == (GIConv) -1)
265244924868 2003-10-19 Brian Masney <masneyb@gftp.org>
masneyb
parents: 281
diff changeset
515 continue;
265244924868 2003-10-19 Brian Masney <masneyb@gftp.org>
masneyb
parents: 281
diff changeset
516
265244924868 2003-10-19 Brian Masney <masneyb@gftp.org>
masneyb
parents: 281
diff changeset
517 error = NULL;
265244924868 2003-10-19 Brian Masney <masneyb@gftp.org>
masneyb
parents: 281
diff changeset
518 if ((ret = g_convert_with_iconv (str, -1, request->iconv, &bread, &bwrite,
265244924868 2003-10-19 Brian Masney <masneyb@gftp.org>
masneyb
parents: 281
diff changeset
519 &error)) == NULL)
265244924868 2003-10-19 Brian Masney <masneyb@gftp.org>
masneyb
parents: 281
diff changeset
520 {
265244924868 2003-10-19 Brian Masney <masneyb@gftp.org>
masneyb
parents: 281
diff changeset
521 g_iconv_close (request->iconv);
265244924868 2003-10-19 Brian Masney <masneyb@gftp.org>
masneyb
parents: 281
diff changeset
522 request->iconv = NULL;
265244924868 2003-10-19 Brian Masney <masneyb@gftp.org>
masneyb
parents: 281
diff changeset
523 continue;
265244924868 2003-10-19 Brian Masney <masneyb@gftp.org>
masneyb
parents: 281
diff changeset
524 }
265244924868 2003-10-19 Brian Masney <masneyb@gftp.org>
masneyb
parents: 281
diff changeset
525 else
265244924868 2003-10-19 Brian Masney <masneyb@gftp.org>
masneyb
parents: 281
diff changeset
526 {
265244924868 2003-10-19 Brian Masney <masneyb@gftp.org>
masneyb
parents: 281
diff changeset
527 request->iconv_initialized = 1;
265244924868 2003-10-19 Brian Masney <masneyb@gftp.org>
masneyb
parents: 281
diff changeset
528 break;
265244924868 2003-10-19 Brian Masney <masneyb@gftp.org>
masneyb
parents: 281
diff changeset
529 }
265244924868 2003-10-19 Brian Masney <masneyb@gftp.org>
masneyb
parents: 281
diff changeset
530 }
265244924868 2003-10-19 Brian Masney <masneyb@gftp.org>
masneyb
parents: 281
diff changeset
531
423
4cee2498761d 2004-3-15 Brian Masney <masneyb@gftp.org>
masneyb
parents: 422
diff changeset
532 g_free (remote_charsets);
4cee2498761d 2004-3-15 Brian Masney <masneyb@gftp.org>
masneyb
parents: 422
diff changeset
533
291
265244924868 2003-10-19 Brian Masney <masneyb@gftp.org>
masneyb
parents: 281
diff changeset
534 return (ret);
265244924868 2003-10-19 Brian Masney <masneyb@gftp.org>
masneyb
parents: 281
diff changeset
535 }
265244924868 2003-10-19 Brian Masney <masneyb@gftp.org>
masneyb
parents: 281
diff changeset
536
265244924868 2003-10-19 Brian Masney <masneyb@gftp.org>
masneyb
parents: 281
diff changeset
537 #else
265244924868 2003-10-19 Brian Masney <masneyb@gftp.org>
masneyb
parents: 281
diff changeset
538
265244924868 2003-10-19 Brian Masney <masneyb@gftp.org>
masneyb
parents: 281
diff changeset
539 char *
265244924868 2003-10-19 Brian Masney <masneyb@gftp.org>
masneyb
parents: 281
diff changeset
540 gftp_string_to_utf8 (gftp_request * request, const char *str)
265244924868 2003-10-19 Brian Masney <masneyb@gftp.org>
masneyb
parents: 281
diff changeset
541 {
265244924868 2003-10-19 Brian Masney <masneyb@gftp.org>
masneyb
parents: 281
diff changeset
542 return (NULL);
265244924868 2003-10-19 Brian Masney <masneyb@gftp.org>
masneyb
parents: 281
diff changeset
543 }
265244924868 2003-10-19 Brian Masney <masneyb@gftp.org>
masneyb
parents: 281
diff changeset
544
265244924868 2003-10-19 Brian Masney <masneyb@gftp.org>
masneyb
parents: 281
diff changeset
545
265244924868 2003-10-19 Brian Masney <masneyb@gftp.org>
masneyb
parents: 281
diff changeset
546 char *
265244924868 2003-10-19 Brian Masney <masneyb@gftp.org>
masneyb
parents: 281
diff changeset
547 gftp_string_from_utf8 (gftp_request * request, const char *str)
265244924868 2003-10-19 Brian Masney <masneyb@gftp.org>
masneyb
parents: 281
diff changeset
548 {
265244924868 2003-10-19 Brian Masney <masneyb@gftp.org>
masneyb
parents: 281
diff changeset
549 return (NULL);
265244924868 2003-10-19 Brian Masney <masneyb@gftp.org>
masneyb
parents: 281
diff changeset
550 }
265244924868 2003-10-19 Brian Masney <masneyb@gftp.org>
masneyb
parents: 281
diff changeset
551
184
65eb40fb4f03 2003-6-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 182
diff changeset
552 #endif
65eb40fb4f03 2003-6-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 182
diff changeset
553
65eb40fb4f03 2003-6-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 182
diff changeset
554
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
555 int
377
14da115b149b 2003-1-23 Brian Masney <masneyb@gftp.org>
masneyb
parents: 372
diff changeset
556 gftp_get_next_file (gftp_request * request, const char *filespec,
14da115b149b 2003-1-23 Brian Masney <masneyb@gftp.org>
masneyb
parents: 372
diff changeset
557 gftp_file * fle)
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
558 {
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
559 int fd, ret;
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
560
84
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 76
diff changeset
561 g_return_val_if_fail (request != NULL, GFTP_EFATAL);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
562
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
563 if (request->get_next_file == NULL)
84
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 76
diff changeset
564 return (GFTP_EFATAL);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
565
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
566 if (request->cached && request->cachefd > 0)
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
567 fd = request->cachefd;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
568 else
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
569 fd = request->datafd;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
570
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
571 memset (fle, 0, sizeof (*fle));
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
572 do
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
573 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
574 gftp_file_destroy (fle);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
575 ret = request->get_next_file (request, fle, fd);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
576
291
265244924868 2003-10-19 Brian Masney <masneyb@gftp.org>
masneyb
parents: 281
diff changeset
577 if (ret >= 0 && fle->file != NULL)
184
65eb40fb4f03 2003-6-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 182
diff changeset
578 fle->utf8_file = gftp_string_to_utf8 (request, fle->file);
45
311e29c40ed6 2002-10-31 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
579
60
8a9324fb63a4 2002-11-21 Brian Masney <masneyb@gftp.org>
masneyb
parents: 58
diff changeset
580 if (ret >= 0 && !request->cached && request->cachefd > 0 &&
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
581 request->last_dir_entry != NULL)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
582 {
168
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 151
diff changeset
583 if (gftp_fd_write (request, request->last_dir_entry,
60
8a9324fb63a4 2002-11-21 Brian Masney <masneyb@gftp.org>
masneyb
parents: 58
diff changeset
584 request->last_dir_entry_len, request->cachefd) < 0)
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
585 {
186
13ca1defdc75 2003-6-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 185
diff changeset
586 request->logging_function (gftp_logging_error, request,
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
587 _("Error: Cannot write to cache: %s\n"),
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
588 g_strerror (errno));
60
8a9324fb63a4 2002-11-21 Brian Masney <masneyb@gftp.org>
masneyb
parents: 58
diff changeset
589 close (request->cachefd);
8a9324fb63a4 2002-11-21 Brian Masney <masneyb@gftp.org>
masneyb
parents: 58
diff changeset
590 request->cachefd = -1;
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
591 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
592 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
593 } while (ret > 0 && !gftp_match_filespec (fle->file, filespec));
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
594
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
595 return (ret);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
596 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
597
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
598
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
599 int
243
b42e7233533a 2003-7-31 Brian Masney <masneyb@gftp.org>
masneyb
parents: 227
diff changeset
600 gftp_parse_bookmark (gftp_request * request, gftp_request * local_request,
275
5810b0f97eee 2003-9-21 Brian Masney <masneyb@gftp.org>
masneyb
parents: 261
diff changeset
601 const char * bookmark, int *refresh_local)
87
6df043359b41 2003-1-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 84
diff changeset
602 {
6df043359b41 2003-1-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 84
diff changeset
603 gftp_logging_func logging_function;
122
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 107
diff changeset
604 gftp_bookmarks_var * tempentry;
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 107
diff changeset
605 char *default_protocol;
173
4c288d05b26a 2003-6-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 169
diff changeset
606 int i, init_ret;
87
6df043359b41 2003-1-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 84
diff changeset
607
6df043359b41 2003-1-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 84
diff changeset
608 g_return_val_if_fail (request != NULL, GFTP_EFATAL);
6df043359b41 2003-1-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 84
diff changeset
609 g_return_val_if_fail (bookmark != NULL, GFTP_EFATAL);
6df043359b41 2003-1-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 84
diff changeset
610
6df043359b41 2003-1-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 84
diff changeset
611 logging_function = request->logging_function;
6df043359b41 2003-1-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 84
diff changeset
612 gftp_request_destroy (request, 0);
6df043359b41 2003-1-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 84
diff changeset
613 request->logging_function = logging_function;
6df043359b41 2003-1-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 84
diff changeset
614
122
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 107
diff changeset
615 if ((tempentry = g_hash_table_lookup (gftp_bookmarks_htable,
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 107
diff changeset
616 bookmark)) == NULL)
87
6df043359b41 2003-1-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 84
diff changeset
617 {
186
13ca1defdc75 2003-6-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 185
diff changeset
618 request->logging_function (gftp_logging_error, request,
87
6df043359b41 2003-1-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 84
diff changeset
619 _("Error: Could not find bookmark %s\n"),
6df043359b41 2003-1-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 84
diff changeset
620 bookmark);
6df043359b41 2003-1-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 84
diff changeset
621 return (GFTP_EFATAL);
6df043359b41 2003-1-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 84
diff changeset
622 }
6df043359b41 2003-1-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 84
diff changeset
623 else if (tempentry->hostname == NULL || *tempentry->hostname == '\0')
6df043359b41 2003-1-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 84
diff changeset
624 {
186
13ca1defdc75 2003-6-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 185
diff changeset
625 request->logging_function (gftp_logging_error, request,
87
6df043359b41 2003-1-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 84
diff changeset
626 _("Bookmarks Error: The bookmark entry %s does not have a hostname\n"), bookmark);
6df043359b41 2003-1-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 84
diff changeset
627 return (GFTP_EFATAL);
6df043359b41 2003-1-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 84
diff changeset
628 }
6df043359b41 2003-1-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 84
diff changeset
629
6df043359b41 2003-1-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 84
diff changeset
630 if (tempentry->user != NULL)
6df043359b41 2003-1-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 84
diff changeset
631 gftp_set_username (request, tempentry->user);
6df043359b41 2003-1-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 84
diff changeset
632
6df043359b41 2003-1-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 84
diff changeset
633 if (tempentry->pass != NULL)
122
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 107
diff changeset
634 gftp_set_password (request, tempentry->pass);
87
6df043359b41 2003-1-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 84
diff changeset
635
6df043359b41 2003-1-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 84
diff changeset
636 if (tempentry->acct != NULL)
6df043359b41 2003-1-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 84
diff changeset
637 gftp_set_account (request, tempentry->acct);
6df043359b41 2003-1-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 84
diff changeset
638
6df043359b41 2003-1-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 84
diff changeset
639 gftp_set_hostname (request, tempentry->hostname);
6df043359b41 2003-1-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 84
diff changeset
640 gftp_set_directory (request, tempentry->remote_dir);
6df043359b41 2003-1-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 84
diff changeset
641 gftp_set_port (request, tempentry->port);
6df043359b41 2003-1-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 84
diff changeset
642
516
fbb5a02beddb 2004-7-26 Brian Masney <masneyb@gftp.org>
masneyb
parents: 512
diff changeset
643 if (local_request != NULL && tempentry->local_dir != NULL &&
243
b42e7233533a 2003-7-31 Brian Masney <masneyb@gftp.org>
masneyb
parents: 227
diff changeset
644 *tempentry->local_dir != '\0')
275
5810b0f97eee 2003-9-21 Brian Masney <masneyb@gftp.org>
masneyb
parents: 261
diff changeset
645 {
5810b0f97eee 2003-9-21 Brian Masney <masneyb@gftp.org>
masneyb
parents: 261
diff changeset
646 gftp_set_directory (local_request, tempentry->local_dir);
516
fbb5a02beddb 2004-7-26 Brian Masney <masneyb@gftp.org>
masneyb
parents: 512
diff changeset
647 if (refresh_local != NULL)
fbb5a02beddb 2004-7-26 Brian Masney <masneyb@gftp.org>
masneyb
parents: 512
diff changeset
648 *refresh_local = 1;
275
5810b0f97eee 2003-9-21 Brian Masney <masneyb@gftp.org>
masneyb
parents: 261
diff changeset
649 }
516
fbb5a02beddb 2004-7-26 Brian Masney <masneyb@gftp.org>
masneyb
parents: 512
diff changeset
650 else if (refresh_local != NULL)
275
5810b0f97eee 2003-9-21 Brian Masney <masneyb@gftp.org>
masneyb
parents: 261
diff changeset
651 *refresh_local = 0;
243
b42e7233533a 2003-7-31 Brian Masney <masneyb@gftp.org>
masneyb
parents: 227
diff changeset
652
87
6df043359b41 2003-1-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 84
diff changeset
653 for (i = 0; gftp_protocols[i].name; i++)
6df043359b41 2003-1-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 84
diff changeset
654 {
6df043359b41 2003-1-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 84
diff changeset
655 if (strcmp (gftp_protocols[i].name, tempentry->protocol) == 0)
6df043359b41 2003-1-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 84
diff changeset
656 {
173
4c288d05b26a 2003-6-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 169
diff changeset
657 if ((init_ret = gftp_protocols[i].init (request)) < 0)
4c288d05b26a 2003-6-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 169
diff changeset
658 {
4c288d05b26a 2003-6-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 169
diff changeset
659 gftp_request_destroy (request, 0);
4c288d05b26a 2003-6-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 169
diff changeset
660 return (init_ret);
4c288d05b26a 2003-6-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 169
diff changeset
661 }
87
6df043359b41 2003-1-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 84
diff changeset
662 break;
6df043359b41 2003-1-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 84
diff changeset
663 }
6df043359b41 2003-1-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 84
diff changeset
664 }
6df043359b41 2003-1-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 84
diff changeset
665
122
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 107
diff changeset
666 if (gftp_protocols[i].name == NULL)
87
6df043359b41 2003-1-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 84
diff changeset
667 {
122
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 107
diff changeset
668 gftp_lookup_request_option (request, "default_protocol",
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 107
diff changeset
669 &default_protocol);
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 107
diff changeset
670
125
b875de05c22d 2003-4-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
671 if (default_protocol != NULL && *default_protocol != '\0')
87
6df043359b41 2003-1-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 84
diff changeset
672 {
122
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 107
diff changeset
673 for (i = 0; gftp_protocols[i].url_prefix; i++)
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 107
diff changeset
674 {
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 107
diff changeset
675 if (strcmp (gftp_protocols[i].name, default_protocol) == 0)
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 107
diff changeset
676 break;
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 107
diff changeset
677 }
87
6df043359b41 2003-1-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 84
diff changeset
678 }
6df043359b41 2003-1-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 84
diff changeset
679
6df043359b41 2003-1-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 84
diff changeset
680 if (gftp_protocols[i].url_prefix == NULL)
6df043359b41 2003-1-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 84
diff changeset
681 i = GFTP_FTP_NUM;
6df043359b41 2003-1-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 84
diff changeset
682 }
6df043359b41 2003-1-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 84
diff changeset
683
199
75eebb3b0592 2003-6-24 Brian Masney <masneyb@gftp.org>
masneyb
parents: 198
diff changeset
684 gftp_copy_local_options (&request->local_options_vars,
75eebb3b0592 2003-6-24 Brian Masney <masneyb@gftp.org>
masneyb
parents: 198
diff changeset
685 &request->local_options_hash,
429
1d45758e5cf5 2004-3-17 Brian Masney <masneyb@gftp.org>
masneyb
parents: 423
diff changeset
686 &request->num_local_options_vars,
199
75eebb3b0592 2003-6-24 Brian Masney <masneyb@gftp.org>
masneyb
parents: 198
diff changeset
687 tempentry->local_options_vars,
75eebb3b0592 2003-6-24 Brian Masney <masneyb@gftp.org>
masneyb
parents: 198
diff changeset
688 tempentry->num_local_options_vars);
75eebb3b0592 2003-6-24 Brian Masney <masneyb@gftp.org>
masneyb
parents: 198
diff changeset
689
173
4c288d05b26a 2003-6-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 169
diff changeset
690 if ((init_ret = gftp_protocols[i].init (request)) < 0)
4c288d05b26a 2003-6-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 169
diff changeset
691 {
4c288d05b26a 2003-6-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 169
diff changeset
692 gftp_request_destroy (request, 0);
4c288d05b26a 2003-6-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 169
diff changeset
693 return (init_ret);
4c288d05b26a 2003-6-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 169
diff changeset
694 }
4c288d05b26a 2003-6-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 169
diff changeset
695
87
6df043359b41 2003-1-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 84
diff changeset
696 return (0);
6df043359b41 2003-1-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 84
diff changeset
697 }
6df043359b41 2003-1-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 84
diff changeset
698
6df043359b41 2003-1-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 84
diff changeset
699
6df043359b41 2003-1-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 84
diff changeset
700 int
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
701 gftp_parse_url (gftp_request * request, const char *url)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
702 {
168
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 151
diff changeset
703 char *pos, *endpos, *endhostpos, tempchar, *default_protocol, *stpos;
67
aa971a4bb16f 2002-11-27 Brian Masney <masneyb@gftp.org>
masneyb
parents: 66
diff changeset
704 gftp_logging_func logging_function;
168
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 151
diff changeset
705 const char *cpos;
518
c6a6e908dbaf 2004-7-27 Brian Masney <masneyb@gftp.org>
masneyb
parents: 516
diff changeset
706 int i, init_ret;
c6a6e908dbaf 2004-7-27 Brian Masney <masneyb@gftp.org>
masneyb
parents: 516
diff changeset
707 size_t len;
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
708
84
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 76
diff changeset
709 g_return_val_if_fail (request != NULL, GFTP_EFATAL);
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 76
diff changeset
710 g_return_val_if_fail (url != NULL, GFTP_EFATAL);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
711
67
aa971a4bb16f 2002-11-27 Brian Masney <masneyb@gftp.org>
masneyb
parents: 66
diff changeset
712 logging_function = request->logging_function;
aa971a4bb16f 2002-11-27 Brian Masney <masneyb@gftp.org>
masneyb
parents: 66
diff changeset
713 gftp_request_destroy (request, 0);
aa971a4bb16f 2002-11-27 Brian Masney <masneyb@gftp.org>
masneyb
parents: 66
diff changeset
714 request->logging_function = logging_function;
aa971a4bb16f 2002-11-27 Brian Masney <masneyb@gftp.org>
masneyb
parents: 66
diff changeset
715
168
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 151
diff changeset
716 for (cpos = url; *cpos == ' '; cpos++);
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 151
diff changeset
717 stpos = g_strdup (cpos);
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 151
diff changeset
718 for (pos = stpos + strlen (stpos) - 1; *pos == ' '; pos--)
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 151
diff changeset
719 *pos = '\0';
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
720
122
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 107
diff changeset
721 i = GFTP_FTP_NUM;
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 107
diff changeset
722
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
723 if ((pos = strstr (stpos, "://")) != NULL)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
724 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
725 *pos = '\0';
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
726
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
727 for (i = 0; gftp_protocols[i].url_prefix; i++)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
728 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
729 if (strcmp (gftp_protocols[i].url_prefix, stpos) == 0)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
730 break;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
731 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
732
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
733 if (gftp_protocols[i].url_prefix == NULL)
168
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 151
diff changeset
734 {
173
4c288d05b26a 2003-6-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 169
diff changeset
735 request->logging_function (gftp_logging_misc, NULL,
4c288d05b26a 2003-6-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 169
diff changeset
736 _("The protocol '%s' is currently not supported.\n"),
4c288d05b26a 2003-6-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 169
diff changeset
737 stpos);
168
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 151
diff changeset
738 g_free (stpos);
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 151
diff changeset
739 return (GFTP_EFATAL);
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 151
diff changeset
740 }
173
4c288d05b26a 2003-6-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 169
diff changeset
741
4c288d05b26a 2003-6-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 169
diff changeset
742 *pos = ':';
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
743 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
744 else
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
745 {
122
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 107
diff changeset
746 gftp_lookup_request_option (request, "default_protocol",
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 107
diff changeset
747 &default_protocol);
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 107
diff changeset
748
125
b875de05c22d 2003-4-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
749 if (default_protocol != NULL && *default_protocol != '\0')
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
750 {
122
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 107
diff changeset
751 for (i = 0; gftp_protocols[i].url_prefix; i++)
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 107
diff changeset
752 {
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 107
diff changeset
753 if (strcmp (gftp_protocols[i].name, default_protocol) == 0)
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 107
diff changeset
754 break;
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 107
diff changeset
755 }
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
756 }
122
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 107
diff changeset
757 }
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
758
122
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 107
diff changeset
759 if (gftp_protocols[i].url_prefix == NULL)
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 107
diff changeset
760 i = GFTP_FTP_NUM;
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
761
173
4c288d05b26a 2003-6-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 169
diff changeset
762 if ((init_ret = gftp_protocols[i].init (request)) < 0)
4c288d05b26a 2003-6-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 169
diff changeset
763 {
4c288d05b26a 2003-6-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 169
diff changeset
764 gftp_request_destroy (request, 0);
4c288d05b26a 2003-6-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 169
diff changeset
765 return (init_ret);
4c288d05b26a 2003-6-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 169
diff changeset
766 }
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
767
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
768 if (request->parse_url != NULL)
168
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 151
diff changeset
769 {
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 151
diff changeset
770 g_free (stpos);
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 151
diff changeset
771 return (request->parse_url (request, url));
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 151
diff changeset
772 }
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 151
diff changeset
773
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 151
diff changeset
774 pos = stpos;
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 151
diff changeset
775 len = strlen (request->url_prefix);
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 151
diff changeset
776 if (strncmp (pos, request->url_prefix, len) == 0 &&
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 151
diff changeset
777 strncmp (pos + len, "://", 3) == 0)
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 151
diff changeset
778 pos += len + 3;
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
779
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
780 if (i == GFTP_LOCAL_NUM)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
781 {
367
d5409bf03ff1 2003-1-18 Brian Masney <masneyb@gftp.org>
masneyb
parents: 359
diff changeset
782 for (; *pos == ' ' || *pos == '\t'; pos++);
168
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 151
diff changeset
783 request->directory = g_strdup (pos);
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 151
diff changeset
784 g_free (stpos);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
785 return (0);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
786 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
787
182
33b394ebba68 2003-6-15 Brian Masney <masneyb@gftp.org>
masneyb
parents: 179
diff changeset
788 if ((endhostpos = strrchr (pos, '@')) != NULL)
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
789 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
790 /* A user/password was entered */
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
791 if ((endpos = strchr (pos, ':')) == NULL || endhostpos < endpos)
168
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 151
diff changeset
792 {
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 151
diff changeset
793 /* No password was entered */
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 151
diff changeset
794 gftp_set_password (request, "");
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 151
diff changeset
795 endpos = endhostpos;
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 151
diff changeset
796 }
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
797
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
798 *endpos = '\0';
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
799 gftp_set_username (request, pos);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
800
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
801 pos = endpos + 1;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
802 if ((endpos = strchr (pos, '@')) != NULL)
168
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 151
diff changeset
803 {
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 151
diff changeset
804 if (strchr (endpos + 1, '@') != NULL)
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 151
diff changeset
805 endpos = strchr (endpos + 1, '@');
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 151
diff changeset
806 *endpos = '\0';
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 151
diff changeset
807 gftp_set_password (request, pos);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
808
168
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 151
diff changeset
809 pos = endpos + 1;
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 151
diff changeset
810 }
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
811 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
812
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
813 /* Now get the hostname and an optional port and optional directory */
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
814 endhostpos = pos + strlen (pos);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
815 if ((endpos = strchr (pos, ':')) != NULL)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
816 endhostpos = endpos;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
817 else if ((endpos = strchr (pos, '/')) != NULL)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
818 endhostpos = endpos;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
819 tempchar = *endhostpos;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
820 *endhostpos = '\0';
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
821 gftp_set_hostname (request, pos);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
822 *endhostpos = tempchar;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
823
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
824 if ((endpos = strchr (pos, ':')) != NULL)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
825 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
826 /* A port was entered */
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
827 pos = endpos + 1;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
828 gftp_set_port (request, strtol (pos, NULL, 10));
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
829 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
830 if ((endpos = strchr (pos, '/')) != NULL)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
831 gftp_set_directory (request, endpos);
168
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 151
diff changeset
832 g_free (stpos);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
833 return (0);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
834 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
835
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
836
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
837 void
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
838 gftp_set_hostname (gftp_request * request, const char *hostname)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
839 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
840 g_return_if_fail (request != NULL);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
841 g_return_if_fail (hostname != NULL);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
842
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
843 if (request->hostname)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
844 g_free (request->hostname);
124
65048c959029 2003-4-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 122
diff changeset
845 request->hostname = g_strdup (hostname);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
846 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
847
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
848
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
849 void
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
850 gftp_set_username (gftp_request * request, const char *username)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
851 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
852 g_return_if_fail (request != NULL);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
853
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
854 if (request->username)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
855 g_free (request->username);
169
d40f9db52cdf 2003-6-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 168
diff changeset
856
d40f9db52cdf 2003-6-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 168
diff changeset
857 if (username != NULL)
d40f9db52cdf 2003-6-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 168
diff changeset
858 request->username = g_strdup (username);
d40f9db52cdf 2003-6-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 168
diff changeset
859 else
d40f9db52cdf 2003-6-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 168
diff changeset
860 request->username = NULL;
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
861 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
862
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
863
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
864 void
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
865 gftp_set_password (gftp_request * request, const char *password)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
866 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
867 g_return_if_fail (request != NULL);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
868
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
869 if (request->password)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
870 g_free (request->password);
169
d40f9db52cdf 2003-6-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 168
diff changeset
871
d40f9db52cdf 2003-6-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 168
diff changeset
872 if (password != NULL)
d40f9db52cdf 2003-6-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 168
diff changeset
873 request->password = g_strdup (password);
d40f9db52cdf 2003-6-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 168
diff changeset
874 else
d40f9db52cdf 2003-6-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 168
diff changeset
875 request->password = NULL;
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
876 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
877
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
878
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
879 void
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
880 gftp_set_account (gftp_request * request, const char *account)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
881 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
882 g_return_if_fail (request != NULL);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
883 g_return_if_fail (account != NULL);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
884
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
885 if (request->account)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
886 g_free (request->account);
124
65048c959029 2003-4-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 122
diff changeset
887 request->account = g_strdup (account);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
888 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
889
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
890
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
891 int
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
892 gftp_set_directory (gftp_request * request, const char *directory)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
893 {
84
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 76
diff changeset
894 g_return_val_if_fail (request != NULL, GFTP_EFATAL);
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 76
diff changeset
895 g_return_val_if_fail (directory != NULL, GFTP_EFATAL);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
896
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
897
169
d40f9db52cdf 2003-6-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 168
diff changeset
898 if (request->datafd <= 0 && !request->always_connected)
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
899 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
900 if (directory != request->directory)
168
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 151
diff changeset
901 {
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 151
diff changeset
902 if (request->directory)
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 151
diff changeset
903 g_free (request->directory);
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 151
diff changeset
904 request->directory = g_strdup (directory);
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 151
diff changeset
905 }
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
906 return (0);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
907 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
908 else if (request->chdir == NULL)
84
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 76
diff changeset
909 return (GFTP_EFATAL);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
910 return (request->chdir (request, directory));
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
911 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
912
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
913
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
914 void
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
915 gftp_set_port (gftp_request * request, unsigned int port)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
916 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
917 g_return_if_fail (request != NULL);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
918
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
919 request->port = port;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
920 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
921
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
922
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
923 int
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
924 gftp_remove_directory (gftp_request * request, const char *directory)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
925 {
84
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 76
diff changeset
926 g_return_val_if_fail (request != NULL, GFTP_EFATAL);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
927
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
928 if (request->rmdir == NULL)
84
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 76
diff changeset
929 return (GFTP_EFATAL);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
930 return (request->rmdir (request, directory));
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
931 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
932
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
933
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
934 int
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
935 gftp_remove_file (gftp_request * request, const char *file)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
936 {
84
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 76
diff changeset
937 g_return_val_if_fail (request != NULL, GFTP_EFATAL);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
938
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
939 if (request->rmfile == NULL)
84
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 76
diff changeset
940 return (GFTP_EFATAL);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
941 return (request->rmfile (request, file));
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
942 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
943
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
944
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
945 int
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
946 gftp_make_directory (gftp_request * request, const char *directory)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
947 {
291
265244924868 2003-10-19 Brian Masney <masneyb@gftp.org>
masneyb
parents: 281
diff changeset
948 char *utf8;
265244924868 2003-10-19 Brian Masney <masneyb@gftp.org>
masneyb
parents: 281
diff changeset
949 int ret;
265244924868 2003-10-19 Brian Masney <masneyb@gftp.org>
masneyb
parents: 281
diff changeset
950
84
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 76
diff changeset
951 g_return_val_if_fail (request != NULL, GFTP_EFATAL);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
952
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
953 if (request->mkdir == NULL)
84
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 76
diff changeset
954 return (GFTP_EFATAL);
291
265244924868 2003-10-19 Brian Masney <masneyb@gftp.org>
masneyb
parents: 281
diff changeset
955
265244924868 2003-10-19 Brian Masney <masneyb@gftp.org>
masneyb
parents: 281
diff changeset
956 utf8 = gftp_string_from_utf8 (request, directory);
265244924868 2003-10-19 Brian Masney <masneyb@gftp.org>
masneyb
parents: 281
diff changeset
957 if (utf8 != NULL)
265244924868 2003-10-19 Brian Masney <masneyb@gftp.org>
masneyb
parents: 281
diff changeset
958 {
265244924868 2003-10-19 Brian Masney <masneyb@gftp.org>
masneyb
parents: 281
diff changeset
959 ret = request->mkdir (request, utf8);
265244924868 2003-10-19 Brian Masney <masneyb@gftp.org>
masneyb
parents: 281
diff changeset
960 g_free (utf8);
265244924868 2003-10-19 Brian Masney <masneyb@gftp.org>
masneyb
parents: 281
diff changeset
961 }
265244924868 2003-10-19 Brian Masney <masneyb@gftp.org>
masneyb
parents: 281
diff changeset
962 else
265244924868 2003-10-19 Brian Masney <masneyb@gftp.org>
masneyb
parents: 281
diff changeset
963 ret = request->mkdir (request, directory);
265244924868 2003-10-19 Brian Masney <masneyb@gftp.org>
masneyb
parents: 281
diff changeset
964
265244924868 2003-10-19 Brian Masney <masneyb@gftp.org>
masneyb
parents: 281
diff changeset
965 return (ret);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
966 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
967
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
968
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
969 int
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
970 gftp_rename_file (gftp_request * request, const char *oldname,
168
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 151
diff changeset
971 const char *newname)
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
972 {
291
265244924868 2003-10-19 Brian Masney <masneyb@gftp.org>
masneyb
parents: 281
diff changeset
973 char *utf8;
265244924868 2003-10-19 Brian Masney <masneyb@gftp.org>
masneyb
parents: 281
diff changeset
974 int ret;
265244924868 2003-10-19 Brian Masney <masneyb@gftp.org>
masneyb
parents: 281
diff changeset
975
84
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 76
diff changeset
976 g_return_val_if_fail (request != NULL, GFTP_EFATAL);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
977
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
978 if (request->rename == NULL)
84
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 76
diff changeset
979 return (GFTP_EFATAL);
291
265244924868 2003-10-19 Brian Masney <masneyb@gftp.org>
masneyb
parents: 281
diff changeset
980
265244924868 2003-10-19 Brian Masney <masneyb@gftp.org>
masneyb
parents: 281
diff changeset
981 utf8 = gftp_string_from_utf8 (request, newname);
265244924868 2003-10-19 Brian Masney <masneyb@gftp.org>
masneyb
parents: 281
diff changeset
982 if (utf8 != NULL)
265244924868 2003-10-19 Brian Masney <masneyb@gftp.org>
masneyb
parents: 281
diff changeset
983 {
265244924868 2003-10-19 Brian Masney <masneyb@gftp.org>
masneyb
parents: 281
diff changeset
984 ret = request->rename (request, oldname, utf8);
265244924868 2003-10-19 Brian Masney <masneyb@gftp.org>
masneyb
parents: 281
diff changeset
985 g_free (utf8);
265244924868 2003-10-19 Brian Masney <masneyb@gftp.org>
masneyb
parents: 281
diff changeset
986 }
265244924868 2003-10-19 Brian Masney <masneyb@gftp.org>
masneyb
parents: 281
diff changeset
987 else
265244924868 2003-10-19 Brian Masney <masneyb@gftp.org>
masneyb
parents: 281
diff changeset
988 ret = request->rename (request, oldname, newname);
265244924868 2003-10-19 Brian Masney <masneyb@gftp.org>
masneyb
parents: 281
diff changeset
989
265244924868 2003-10-19 Brian Masney <masneyb@gftp.org>
masneyb
parents: 281
diff changeset
990 return (ret);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
991 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
992
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
993
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
994 int
499
39e9945288ea 2004-7-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 498
diff changeset
995 gftp_chmod (gftp_request * request, const char *file, mode_t mode)
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
996 {
84
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 76
diff changeset
997 g_return_val_if_fail (request != NULL, GFTP_EFATAL);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
998
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
999 if (request->chmod == NULL)
84
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 76
diff changeset
1000 return (GFTP_EFATAL);
504
93d7d3b9a477 2004-7-18 Brian Masney <masneyb@gftp.org>
masneyb
parents: 500
diff changeset
1001
93d7d3b9a477 2004-7-18 Brian Masney <masneyb@gftp.org>
masneyb
parents: 500
diff changeset
1002 mode &= S_IRWXU | S_IRWXG | S_IRWXO | S_ISUID | S_ISGID | S_ISVTX;
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1003 return (request->chmod (request, file, mode));
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1004 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1005
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1006
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1007 int
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1008 gftp_set_file_time (gftp_request * request, const char *file, time_t datetime)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1009 {
84
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 76
diff changeset
1010 g_return_val_if_fail (request != NULL, GFTP_EFATAL);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1011
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1012 if (request->set_file_time == NULL)
84
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 76
diff changeset
1013 return (GFTP_EFATAL);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1014 return (request->set_file_time (request, file, datetime));
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1015 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1016
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1017
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1018 char
478
97fd5eb34be0 2004-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 473
diff changeset
1019 gftp_site_cmd (gftp_request * request, int specify_site, const char *command)
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1020 {
84
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 76
diff changeset
1021 g_return_val_if_fail (request != NULL, GFTP_EFATAL);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1022
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1023 if (request->site == NULL)
84
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 76
diff changeset
1024 return (GFTP_EFATAL);
478
97fd5eb34be0 2004-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 473
diff changeset
1025 return (request->site (request, specify_site, command));
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1026 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1027
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1028
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
1029 off_t
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1030 gftp_get_file_size (gftp_request * request, const char *filename)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1031 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1032 g_return_val_if_fail (request != NULL, 0);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1033
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1034 if (request->get_file_size == NULL)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1035 return (0);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1036 return (request->get_file_size (request, filename));
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1037 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1038
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1039
122
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 107
diff changeset
1040 static int
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 107
diff changeset
1041 gftp_need_proxy (gftp_request * request, char *service, char *proxy_hostname,
518
c6a6e908dbaf 2004-7-27 Brian Masney <masneyb@gftp.org>
masneyb
parents: 516
diff changeset
1042 unsigned int proxy_port)
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1043 {
122
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 107
diff changeset
1044 gftp_config_list_vars * proxy_hosts;
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1045 gftp_proxy_hosts * hostname;
460
075f89b4395c 2004-4-14 Brian Masney <masneyb@gftp.org>
masneyb
parents: 451
diff changeset
1046 size_t hostlen, domlen;
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1047 unsigned char addy[4];
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1048 struct sockaddr *addr;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1049 GList * templist;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1050 gint32 netaddr;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1051 char *pos;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1052 #if defined (HAVE_GETADDRINFO) && defined (HAVE_GAI_STRERROR)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1053 struct addrinfo hints;
516
fbb5a02beddb 2004-7-26 Brian Masney <masneyb@gftp.org>
masneyb
parents: 512
diff changeset
1054 unsigned int port;
fbb5a02beddb 2004-7-26 Brian Masney <masneyb@gftp.org>
masneyb
parents: 512
diff changeset
1055 int errnum;
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1056 char serv[8];
122
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 107
diff changeset
1057 #endif
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 107
diff changeset
1058
218
de6a2e8e51cb 2003-7-9 Brian Masney <masneyb@gftp.org>
masneyb
parents: 215
diff changeset
1059 gftp_lookup_global_option ("dont_use_proxy", &proxy_hosts);
122
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 107
diff changeset
1060
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 107
diff changeset
1061 if (proxy_hostname == NULL || *proxy_hostname == '\0')
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 107
diff changeset
1062 return (0);
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 107
diff changeset
1063 else if (proxy_hosts->list == NULL)
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 107
diff changeset
1064 return (proxy_hostname != NULL &&
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 107
diff changeset
1065 *proxy_hostname != '\0');
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1066
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1067 request->hostp = NULL;
122
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 107
diff changeset
1068 #if defined (HAVE_GETADDRINFO) && defined (HAVE_GAI_STRERROR)
151
2f15b3000dbc 2003-4-27 Brian Masney <masneyb@gftp.org>
masneyb
parents: 146
diff changeset
1069 request->free_hostp = 1;
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1070 memset (&hints, 0, sizeof (hints));
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1071 hints.ai_flags = AI_CANONNAME;
146
782f84694489 2003-4-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 143
diff changeset
1072 hints.ai_family = PF_UNSPEC;
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1073 hints.ai_socktype = SOCK_STREAM;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1074
122
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 107
diff changeset
1075 port = request->use_proxy ? proxy_port : request->port;
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1076 if (port == 0)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1077 strcpy (serv, service);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1078 else
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1079 snprintf (serv, sizeof (serv), "%d", port);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1080
186
13ca1defdc75 2003-6-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 185
diff changeset
1081 request->logging_function (gftp_logging_misc, request,
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1082 _("Looking up %s\n"), request->hostname);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1083
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1084 if ((errnum = getaddrinfo (request->hostname, serv, &hints,
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1085 &request->hostp)) != 0)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1086 {
186
13ca1defdc75 2003-6-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 185
diff changeset
1087 request->logging_function (gftp_logging_error, request,
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1088 _("Cannot look up hostname %s: %s\n"),
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1089 request->hostname, gai_strerror (errnum));
84
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 76
diff changeset
1090 return (GFTP_ERETRYABLE);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1091 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1092
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1093 addr = request->hostp->ai_addr;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1094
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1095 #else /* !HAVE_GETADDRINFO */
186
13ca1defdc75 2003-6-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 185
diff changeset
1096 request->logging_function (gftp_logging_misc, request,
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1097 _("Looking up %s\n"), request->hostname);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1098
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1099 if (!(request->hostp = r_gethostbyname (request->hostname, &request->host,
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1100 NULL)))
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1101 {
186
13ca1defdc75 2003-6-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 185
diff changeset
1102 request->logging_function (gftp_logging_error, request,
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1103 _("Cannot look up hostname %s: %s\n"),
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1104 request->hostname, g_strerror (errno));
84
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 76
diff changeset
1105 return (GFTP_ERETRYABLE);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1106 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1107
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1108 addr = (struct sockaddr *) request->host.h_addr_list[0];
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1109
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1110 #endif /* HAVE_GETADDRINFO */
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1111
122
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 107
diff changeset
1112 templist = proxy_hosts->list;
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1113 while (templist != NULL)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1114 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1115 hostname = templist->data;
460
075f89b4395c 2004-4-14 Brian Masney <masneyb@gftp.org>
masneyb
parents: 451
diff changeset
1116 if (hostname->domain != NULL)
168
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 151
diff changeset
1117 {
460
075f89b4395c 2004-4-14 Brian Masney <masneyb@gftp.org>
masneyb
parents: 451
diff changeset
1118 hostlen = strlen (request->hostname);
075f89b4395c 2004-4-14 Brian Masney <masneyb@gftp.org>
masneyb
parents: 451
diff changeset
1119 domlen = strlen (hostname->domain);
075f89b4395c 2004-4-14 Brian Masney <masneyb@gftp.org>
masneyb
parents: 451
diff changeset
1120 if (hostlen > domlen)
075f89b4395c 2004-4-14 Brian Masney <masneyb@gftp.org>
masneyb
parents: 451
diff changeset
1121 {
075f89b4395c 2004-4-14 Brian Masney <masneyb@gftp.org>
masneyb
parents: 451
diff changeset
1122 pos = request->hostname + hostlen - domlen;
075f89b4395c 2004-4-14 Brian Masney <masneyb@gftp.org>
masneyb
parents: 451
diff changeset
1123 if (strcmp (hostname->domain, pos) == 0)
075f89b4395c 2004-4-14 Brian Masney <masneyb@gftp.org>
masneyb
parents: 451
diff changeset
1124 return (0);
075f89b4395c 2004-4-14 Brian Masney <masneyb@gftp.org>
masneyb
parents: 451
diff changeset
1125 }
168
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 151
diff changeset
1126 }
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1127
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1128 if (hostname->ipv4_network_address != 0)
168
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 151
diff changeset
1129 {
516
fbb5a02beddb 2004-7-26 Brian Masney <masneyb@gftp.org>
masneyb
parents: 512
diff changeset
1130 memcpy (addy, addr, sizeof (*addy));
168
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 151
diff changeset
1131 netaddr =
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 151
diff changeset
1132 (((addy[0] & 0xff) << 24) | ((addy[1] & 0xff) << 16) |
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 151
diff changeset
1133 ((addy[2] & 0xff) << 8) | (addy[3] & 0xff)) &
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1134 hostname->ipv4_netmask;
168
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 151
diff changeset
1135 if (netaddr == hostname->ipv4_network_address)
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 151
diff changeset
1136 return (0);
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 151
diff changeset
1137 }
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1138 templist = templist->next;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1139 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1140
122
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 107
diff changeset
1141 return (proxy_hostname != NULL && *proxy_hostname != '\0');
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1142 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1143
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1144
48
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 46
diff changeset
1145 static char *
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 46
diff changeset
1146 copy_token (char **dest, char *source)
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1147 {
48
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 46
diff changeset
1148 /* This function is used internally by gftp_parse_ls () */
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 46
diff changeset
1149 char *endpos, savepos;
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1150
48
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 46
diff changeset
1151 endpos = source;
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 46
diff changeset
1152 while (*endpos != ' ' && *endpos != '\t' && *endpos != '\0')
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 46
diff changeset
1153 endpos++;
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 46
diff changeset
1154 if (*endpos == '\0')
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 46
diff changeset
1155 return (NULL);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1156
48
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 46
diff changeset
1157 savepos = *endpos;
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 46
diff changeset
1158 *endpos = '\0';
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 46
diff changeset
1159 *dest = g_malloc (endpos - source + 1);
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 46
diff changeset
1160 strcpy (*dest, source);
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 46
diff changeset
1161 *endpos = savepos;
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1162
48
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 46
diff changeset
1163 /* Skip the blanks till we get to the next entry */
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 46
diff changeset
1164 source = endpos + 1;
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 46
diff changeset
1165 while ((*source == ' ' || *source == '\t') && *source != '\0')
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 46
diff changeset
1166 source++;
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 46
diff changeset
1167 return (source);
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 46
diff changeset
1168 }
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1169
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1170
48
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 46
diff changeset
1171 static char *
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 46
diff changeset
1172 goto_next_token (char *pos)
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 46
diff changeset
1173 {
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 46
diff changeset
1174 while (*pos != ' ' && *pos != '\t' && *pos != '\0')
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 46
diff changeset
1175 pos++;
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1176
516
fbb5a02beddb 2004-7-26 Brian Masney <masneyb@gftp.org>
masneyb
parents: 512
diff changeset
1177 while (*pos == ' ' || *pos == '\t')
48
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 46
diff changeset
1178 pos++;
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 46
diff changeset
1179
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 46
diff changeset
1180 return (pos);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1181 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1182
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1183
485
7334a74db6f6 2004-6-15 Brian Masney <masneyb@gftp.org>
masneyb
parents: 480
diff changeset
1184 static time_t
7334a74db6f6 2004-6-15 Brian Masney <masneyb@gftp.org>
masneyb
parents: 480
diff changeset
1185 parse_vms_time (char *str, char **endpos)
7334a74db6f6 2004-6-15 Brian Masney <masneyb@gftp.org>
masneyb
parents: 480
diff changeset
1186 {
7334a74db6f6 2004-6-15 Brian Masney <masneyb@gftp.org>
masneyb
parents: 480
diff changeset
1187 struct tm curtime;
7334a74db6f6 2004-6-15 Brian Masney <masneyb@gftp.org>
masneyb
parents: 480
diff changeset
1188 time_t ret;
7334a74db6f6 2004-6-15 Brian Masney <masneyb@gftp.org>
masneyb
parents: 480
diff changeset
1189
7334a74db6f6 2004-6-15 Brian Masney <masneyb@gftp.org>
masneyb
parents: 480
diff changeset
1190 /* 8-JUN-2004 13:04:14 */
7334a74db6f6 2004-6-15 Brian Masney <masneyb@gftp.org>
masneyb
parents: 480
diff changeset
1191 memset (&curtime, 0, sizeof (curtime));
7334a74db6f6 2004-6-15 Brian Masney <masneyb@gftp.org>
masneyb
parents: 480
diff changeset
1192
7334a74db6f6 2004-6-15 Brian Masney <masneyb@gftp.org>
masneyb
parents: 480
diff changeset
1193 *endpos = strptime (str, "%d-%b-%Y %H:%M:%S", &curtime);
7334a74db6f6 2004-6-15 Brian Masney <masneyb@gftp.org>
masneyb
parents: 480
diff changeset
1194 if (*endpos == NULL)
7334a74db6f6 2004-6-15 Brian Masney <masneyb@gftp.org>
masneyb
parents: 480
diff changeset
1195 *endpos = strptime (str, "%d-%b-%Y %H:%M", &curtime);
7334a74db6f6 2004-6-15 Brian Masney <masneyb@gftp.org>
masneyb
parents: 480
diff changeset
1196
7334a74db6f6 2004-6-15 Brian Masney <masneyb@gftp.org>
masneyb
parents: 480
diff changeset
1197 if (*endpos != NULL)
7334a74db6f6 2004-6-15 Brian Masney <masneyb@gftp.org>
masneyb
parents: 480
diff changeset
1198 {
7334a74db6f6 2004-6-15 Brian Masney <masneyb@gftp.org>
masneyb
parents: 480
diff changeset
1199 ret = mktime (&curtime);
7334a74db6f6 2004-6-15 Brian Masney <masneyb@gftp.org>
masneyb
parents: 480
diff changeset
1200 for (; **endpos == ' ' || **endpos == '\t'; (*endpos)++);
7334a74db6f6 2004-6-15 Brian Masney <masneyb@gftp.org>
masneyb
parents: 480
diff changeset
1201 }
7334a74db6f6 2004-6-15 Brian Masney <masneyb@gftp.org>
masneyb
parents: 480
diff changeset
1202 else
7334a74db6f6 2004-6-15 Brian Masney <masneyb@gftp.org>
masneyb
parents: 480
diff changeset
1203 {
7334a74db6f6 2004-6-15 Brian Masney <masneyb@gftp.org>
masneyb
parents: 480
diff changeset
1204 ret = 0;
7334a74db6f6 2004-6-15 Brian Masney <masneyb@gftp.org>
masneyb
parents: 480
diff changeset
1205 *endpos = goto_next_token (str);
7334a74db6f6 2004-6-15 Brian Masney <masneyb@gftp.org>
masneyb
parents: 480
diff changeset
1206 if (*endpos != NULL)
7334a74db6f6 2004-6-15 Brian Masney <masneyb@gftp.org>
masneyb
parents: 480
diff changeset
1207 *endpos = goto_next_token (*endpos);
7334a74db6f6 2004-6-15 Brian Masney <masneyb@gftp.org>
masneyb
parents: 480
diff changeset
1208 }
7334a74db6f6 2004-6-15 Brian Masney <masneyb@gftp.org>
masneyb
parents: 480
diff changeset
1209
7334a74db6f6 2004-6-15 Brian Masney <masneyb@gftp.org>
masneyb
parents: 480
diff changeset
1210 return (ret);
7334a74db6f6 2004-6-15 Brian Masney <masneyb@gftp.org>
masneyb
parents: 480
diff changeset
1211 }
7334a74db6f6 2004-6-15 Brian Masney <masneyb@gftp.org>
masneyb
parents: 480
diff changeset
1212
7334a74db6f6 2004-6-15 Brian Masney <masneyb@gftp.org>
masneyb
parents: 480
diff changeset
1213
102
3b573c8ef706 2003-2-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 91
diff changeset
1214 time_t
3b573c8ef706 2003-2-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 91
diff changeset
1215 parse_time (char *str, char **endpos)
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1216 {
102
3b573c8ef706 2003-2-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 91
diff changeset
1217 struct tm curtime, *loctime;
105
ae13b18c9336 2003-2-9 Brian Masney <masneyb@gftp.org>
masneyb
parents: 102
diff changeset
1218 time_t t, ret;
102
3b573c8ef706 2003-2-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 91
diff changeset
1219 char *tmppos;
460
075f89b4395c 2004-4-14 Brian Masney <masneyb@gftp.org>
masneyb
parents: 451
diff changeset
1220 size_t slen;
260
71d0098c3735 2003-8-17 Brian Masney <masneyb@gftp.org>
masneyb
parents: 249
diff changeset
1221 int i, num;
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1222
460
075f89b4395c 2004-4-14 Brian Masney <masneyb@gftp.org>
masneyb
parents: 451
diff changeset
1223 slen = strlen (str);
102
3b573c8ef706 2003-2-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 91
diff changeset
1224 memset (&curtime, 0, sizeof (curtime));
3b573c8ef706 2003-2-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 91
diff changeset
1225 curtime.tm_isdst = -1;
460
075f89b4395c 2004-4-14 Brian Masney <masneyb@gftp.org>
masneyb
parents: 451
diff changeset
1226
075f89b4395c 2004-4-14 Brian Masney <masneyb@gftp.org>
masneyb
parents: 451
diff changeset
1227 if (slen > 4 && isdigit ((int) str[0]) && str[2] == '-' &&
260
71d0098c3735 2003-8-17 Brian Masney <masneyb@gftp.org>
masneyb
parents: 249
diff changeset
1228 isdigit ((int) str[3]))
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1229 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1230 /* This is how DOS will return the date/time */
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1231 /* 07-06-99 12:57PM */
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1232
102
3b573c8ef706 2003-2-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 91
diff changeset
1233 tmppos = strptime (str, "%m-%d-%y %I:%M%p", &curtime);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1234 }
460
075f89b4395c 2004-4-14 Brian Masney <masneyb@gftp.org>
masneyb
parents: 451
diff changeset
1235 else if (slen > 4 && isdigit ((int) str[0]) && str[2] == '-' &&
260
71d0098c3735 2003-8-17 Brian Masney <masneyb@gftp.org>
masneyb
parents: 249
diff changeset
1236 isalpha (str[3]))
105
ae13b18c9336 2003-2-9 Brian Masney <masneyb@gftp.org>
masneyb
parents: 102
diff changeset
1237 {
ae13b18c9336 2003-2-9 Brian Masney <masneyb@gftp.org>
masneyb
parents: 102
diff changeset
1238 /* 10-Jan-2003 09:14 */
ae13b18c9336 2003-2-9 Brian Masney <masneyb@gftp.org>
masneyb
parents: 102
diff changeset
1239 tmppos = strptime (str, "%d-%h-%Y %H:%M", &curtime);
ae13b18c9336 2003-2-9 Brian Masney <masneyb@gftp.org>
masneyb
parents: 102
diff changeset
1240 }
460
075f89b4395c 2004-4-14 Brian Masney <masneyb@gftp.org>
masneyb
parents: 451
diff changeset
1241 else if (slen > 4 && isdigit ((int) str[0]) && str[4] == '/')
358
28a50fb598ed 2003-1-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 356
diff changeset
1242 {
28a50fb598ed 2003-1-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 356
diff changeset
1243 /* 2003/12/25 */
28a50fb598ed 2003-1-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 356
diff changeset
1244 tmppos = strptime (str, "%Y/%m/%d", &curtime);
28a50fb598ed 2003-1-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 356
diff changeset
1245 }
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1246 else
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1247 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1248 /* This is how most UNIX, Novell, and MacOS ftp servers send their time */
102
3b573c8ef706 2003-2-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 91
diff changeset
1249 /* Jul 06 12:57 or Jul 6 1999 */
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1250
102
3b573c8ef706 2003-2-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 91
diff changeset
1251 if (strchr (str, ':') != NULL)
3b573c8ef706 2003-2-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 91
diff changeset
1252 {
3b573c8ef706 2003-2-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 91
diff changeset
1253 tmppos = strptime (str, "%h %d %H:%M", &curtime);
3b573c8ef706 2003-2-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 91
diff changeset
1254 t = time (NULL);
3b573c8ef706 2003-2-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 91
diff changeset
1255 loctime = localtime (&t);
359
52c5ee1fa455 2003-1-7 Brian Masney <masneyb@gftp.org>
masneyb
parents: 358
diff changeset
1256
52c5ee1fa455 2003-1-7 Brian Masney <masneyb@gftp.org>
masneyb
parents: 358
diff changeset
1257 if (curtime.tm_mon > loctime->tm_mon)
52c5ee1fa455 2003-1-7 Brian Masney <masneyb@gftp.org>
masneyb
parents: 358
diff changeset
1258 curtime.tm_year = loctime->tm_year - 1;
52c5ee1fa455 2003-1-7 Brian Masney <masneyb@gftp.org>
masneyb
parents: 358
diff changeset
1259 else
52c5ee1fa455 2003-1-7 Brian Masney <masneyb@gftp.org>
masneyb
parents: 358
diff changeset
1260 curtime.tm_year = loctime->tm_year;
102
3b573c8ef706 2003-2-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 91
diff changeset
1261 }
3b573c8ef706 2003-2-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 91
diff changeset
1262 else
3b573c8ef706 2003-2-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 91
diff changeset
1263 tmppos = strptime (str, "%h %d %Y", &curtime);
3b573c8ef706 2003-2-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 91
diff changeset
1264 }
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1265
105
ae13b18c9336 2003-2-9 Brian Masney <masneyb@gftp.org>
masneyb
parents: 102
diff changeset
1266 if (tmppos != NULL)
ae13b18c9336 2003-2-9 Brian Masney <masneyb@gftp.org>
masneyb
parents: 102
diff changeset
1267 ret = mktime (&curtime);
ae13b18c9336 2003-2-9 Brian Masney <masneyb@gftp.org>
masneyb
parents: 102
diff changeset
1268 else
ae13b18c9336 2003-2-9 Brian Masney <masneyb@gftp.org>
masneyb
parents: 102
diff changeset
1269 ret = 0;
ae13b18c9336 2003-2-9 Brian Masney <masneyb@gftp.org>
masneyb
parents: 102
diff changeset
1270
102
3b573c8ef706 2003-2-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 91
diff changeset
1271 if (endpos != NULL)
105
ae13b18c9336 2003-2-9 Brian Masney <masneyb@gftp.org>
masneyb
parents: 102
diff changeset
1272 {
ae13b18c9336 2003-2-9 Brian Masney <masneyb@gftp.org>
masneyb
parents: 102
diff changeset
1273 if (tmppos == NULL)
ae13b18c9336 2003-2-9 Brian Masney <masneyb@gftp.org>
masneyb
parents: 102
diff changeset
1274 {
260
71d0098c3735 2003-8-17 Brian Masney <masneyb@gftp.org>
masneyb
parents: 249
diff changeset
1275 /* We cannot parse this date format. So, just skip this date field
71d0098c3735 2003-8-17 Brian Masney <masneyb@gftp.org>
masneyb
parents: 249
diff changeset
1276 and continue to the next token. This is mainly for the HTTP
71d0098c3735 2003-8-17 Brian Masney <masneyb@gftp.org>
masneyb
parents: 249
diff changeset
1277 support */
71d0098c3735 2003-8-17 Brian Masney <masneyb@gftp.org>
masneyb
parents: 249
diff changeset
1278
71d0098c3735 2003-8-17 Brian Masney <masneyb@gftp.org>
masneyb
parents: 249
diff changeset
1279 *endpos = str;
71d0098c3735 2003-8-17 Brian Masney <masneyb@gftp.org>
masneyb
parents: 249
diff changeset
1280 for (num = 0; num < 2 && **endpos != '\0'; num++)
71d0098c3735 2003-8-17 Brian Masney <masneyb@gftp.org>
masneyb
parents: 249
diff changeset
1281 {
71d0098c3735 2003-8-17 Brian Masney <masneyb@gftp.org>
masneyb
parents: 249
diff changeset
1282 for (i=0;
71d0098c3735 2003-8-17 Brian Masney <masneyb@gftp.org>
masneyb
parents: 249
diff changeset
1283 (*endpos)[i] != ' ' && (*endpos)[i] != '\t' &&
71d0098c3735 2003-8-17 Brian Masney <masneyb@gftp.org>
masneyb
parents: 249
diff changeset
1284 (*endpos)[i] != '\0';
71d0098c3735 2003-8-17 Brian Masney <masneyb@gftp.org>
masneyb
parents: 249
diff changeset
1285 i++);
71d0098c3735 2003-8-17 Brian Masney <masneyb@gftp.org>
masneyb
parents: 249
diff changeset
1286 *endpos += i;
71d0098c3735 2003-8-17 Brian Masney <masneyb@gftp.org>
masneyb
parents: 249
diff changeset
1287
71d0098c3735 2003-8-17 Brian Masney <masneyb@gftp.org>
masneyb
parents: 249
diff changeset
1288 for (i=0; (*endpos)[i] == ' ' || (*endpos)[i] == '\t'; i++);
71d0098c3735 2003-8-17 Brian Masney <masneyb@gftp.org>
masneyb
parents: 249
diff changeset
1289 *endpos += i;
71d0098c3735 2003-8-17 Brian Masney <masneyb@gftp.org>
masneyb
parents: 249
diff changeset
1290 }
105
ae13b18c9336 2003-2-9 Brian Masney <masneyb@gftp.org>
masneyb
parents: 102
diff changeset
1291 }
ae13b18c9336 2003-2-9 Brian Masney <masneyb@gftp.org>
masneyb
parents: 102
diff changeset
1292 else
ae13b18c9336 2003-2-9 Brian Masney <masneyb@gftp.org>
masneyb
parents: 102
diff changeset
1293 *endpos = tmppos;
ae13b18c9336 2003-2-9 Brian Masney <masneyb@gftp.org>
masneyb
parents: 102
diff changeset
1294 }
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1295
281
1c7cde8a3a53 2003-10-4 Brian Masney <masneyb@gftp.org>
masneyb
parents: 275
diff changeset
1296 return (ret);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1297 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1298
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1299
499
39e9945288ea 2004-7-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 498
diff changeset
1300 static mode_t
39e9945288ea 2004-7-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 498
diff changeset
1301 gftp_parse_vms_attribs (char **src, mode_t mask)
107
982e3890e7fe 2003-2-17 Brian Masney <masneyb@gftp.org>
masneyb
parents: 105
diff changeset
1302 {
982e3890e7fe 2003-2-17 Brian Masney <masneyb@gftp.org>
masneyb
parents: 105
diff changeset
1303 char *endpos;
499
39e9945288ea 2004-7-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 498
diff changeset
1304 mode_t ret;
107
982e3890e7fe 2003-2-17 Brian Masney <masneyb@gftp.org>
masneyb
parents: 105
diff changeset
1305
982e3890e7fe 2003-2-17 Brian Masney <masneyb@gftp.org>
masneyb
parents: 105
diff changeset
1306 if (*src == NULL)
499
39e9945288ea 2004-7-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 498
diff changeset
1307 return (0);
107
982e3890e7fe 2003-2-17 Brian Masney <masneyb@gftp.org>
masneyb
parents: 105
diff changeset
1308
982e3890e7fe 2003-2-17 Brian Masney <masneyb@gftp.org>
masneyb
parents: 105
diff changeset
1309 if ((endpos = strchr (*src, ',')) != NULL)
982e3890e7fe 2003-2-17 Brian Masney <masneyb@gftp.org>
masneyb
parents: 105
diff changeset
1310 *endpos = '\0';
982e3890e7fe 2003-2-17 Brian Masney <masneyb@gftp.org>
masneyb
parents: 105
diff changeset
1311
499
39e9945288ea 2004-7-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 498
diff changeset
1312 ret = 0;
107
982e3890e7fe 2003-2-17 Brian Masney <masneyb@gftp.org>
masneyb
parents: 105
diff changeset
1313 if (strchr (*src, 'R') != NULL)
499
39e9945288ea 2004-7-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 498
diff changeset
1314 ret |= S_IRUSR | S_IRGRP | S_IROTH;
107
982e3890e7fe 2003-2-17 Brian Masney <masneyb@gftp.org>
masneyb
parents: 105
diff changeset
1315 if (strchr (*src, 'W') != NULL)
499
39e9945288ea 2004-7-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 498
diff changeset
1316 ret |= S_IWUSR | S_IWGRP | S_IWOTH;
107
982e3890e7fe 2003-2-17 Brian Masney <masneyb@gftp.org>
masneyb
parents: 105
diff changeset
1317 if (strchr (*src, 'E') != NULL)
499
39e9945288ea 2004-7-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 498
diff changeset
1318 ret |= S_IXUSR | S_IXGRP | S_IXOTH;
107
982e3890e7fe 2003-2-17 Brian Masney <masneyb@gftp.org>
masneyb
parents: 105
diff changeset
1319
982e3890e7fe 2003-2-17 Brian Masney <masneyb@gftp.org>
masneyb
parents: 105
diff changeset
1320 *src = endpos + 1;
499
39e9945288ea 2004-7-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 498
diff changeset
1321
39e9945288ea 2004-7-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 498
diff changeset
1322 return (ret & mask);
107
982e3890e7fe 2003-2-17 Brian Masney <masneyb@gftp.org>
masneyb
parents: 105
diff changeset
1323 }
982e3890e7fe 2003-2-17 Brian Masney <masneyb@gftp.org>
masneyb
parents: 105
diff changeset
1324
982e3890e7fe 2003-2-17 Brian Masney <masneyb@gftp.org>
masneyb
parents: 105
diff changeset
1325
982e3890e7fe 2003-2-17 Brian Masney <masneyb@gftp.org>
masneyb
parents: 105
diff changeset
1326 static int
485
7334a74db6f6 2004-6-15 Brian Masney <masneyb@gftp.org>
masneyb
parents: 480
diff changeset
1327 gftp_parse_ls_vms (gftp_request * request, int fd, char *str, gftp_file * fle)
107
982e3890e7fe 2003-2-17 Brian Masney <masneyb@gftp.org>
masneyb
parents: 105
diff changeset
1328 {
485
7334a74db6f6 2004-6-15 Brian Masney <masneyb@gftp.org>
masneyb
parents: 480
diff changeset
1329 char *curpos, *endpos, tempstr[1024];
7334a74db6f6 2004-6-15 Brian Masney <masneyb@gftp.org>
masneyb
parents: 480
diff changeset
1330 int multiline;
7334a74db6f6 2004-6-15 Brian Masney <masneyb@gftp.org>
masneyb
parents: 480
diff changeset
1331 ssize_t len;
107
982e3890e7fe 2003-2-17 Brian Masney <masneyb@gftp.org>
masneyb
parents: 105
diff changeset
1332
982e3890e7fe 2003-2-17 Brian Masney <masneyb@gftp.org>
masneyb
parents: 105
diff changeset
1333 /* .PINE-DEBUG1;1 9 21-AUG-2002 20:06 [MYERSRG] (RWED,RWED,,) */
982e3890e7fe 2003-2-17 Brian Masney <masneyb@gftp.org>
masneyb
parents: 105
diff changeset
1334 /* WWW.DIR;1 1 23-NOV-1999 05:47 [MYERSRG] (RWE,RWE,RE,E) */
982e3890e7fe 2003-2-17 Brian Masney <masneyb@gftp.org>
masneyb
parents: 105
diff changeset
1335
485
7334a74db6f6 2004-6-15 Brian Masney <masneyb@gftp.org>
masneyb
parents: 480
diff changeset
1336 /* Multiline VMS
7334a74db6f6 2004-6-15 Brian Masney <masneyb@gftp.org>
masneyb
parents: 480
diff changeset
1337 $MAIN.TPU$JOURNAL;1
7334a74db6f6 2004-6-15 Brian Masney <masneyb@gftp.org>
masneyb
parents: 480
diff changeset
1338 1/18 8-JUN-2004 13:04:14 [NUCLEAR,FISSION] (RWED,RWED,RE,)
7334a74db6f6 2004-6-15 Brian Masney <masneyb@gftp.org>
masneyb
parents: 480
diff changeset
1339 TCPIP$FTP_SERVER.LOG;29
7334a74db6f6 2004-6-15 Brian Masney <masneyb@gftp.org>
masneyb
parents: 480
diff changeset
1340 0/18 8-JUN-2004 14:42:04 [NUCLEAR,FISSION] (RWED,RWED,RE,)
7334a74db6f6 2004-6-15 Brian Masney <masneyb@gftp.org>
masneyb
parents: 480
diff changeset
1341 TCPIP$FTP_SERVER.LOG;28
7334a74db6f6 2004-6-15 Brian Masney <masneyb@gftp.org>
masneyb
parents: 480
diff changeset
1342 5/18 8-JUN-2004 13:05:11 [NUCLEAR,FISSION] (RWED,RWED,RE,)
7334a74db6f6 2004-6-15 Brian Masney <masneyb@gftp.org>
masneyb
parents: 480
diff changeset
1343 TCPIP$FTP_SERVER.LOG;27
7334a74db6f6 2004-6-15 Brian Masney <masneyb@gftp.org>
masneyb
parents: 480
diff changeset
1344 5/18 8-JUN-2004 13:03:51 [NUCLEAR,FISSION] (RWED,RWED,RE,) */
7334a74db6f6 2004-6-15 Brian Masney <masneyb@gftp.org>
masneyb
parents: 480
diff changeset
1345
107
982e3890e7fe 2003-2-17 Brian Masney <masneyb@gftp.org>
masneyb
parents: 105
diff changeset
1346 if ((curpos = strchr (str, ';')) == NULL)
982e3890e7fe 2003-2-17 Brian Masney <masneyb@gftp.org>
masneyb
parents: 105
diff changeset
1347 return (GFTP_EFATAL);
982e3890e7fe 2003-2-17 Brian Masney <masneyb@gftp.org>
masneyb
parents: 105
diff changeset
1348
485
7334a74db6f6 2004-6-15 Brian Masney <masneyb@gftp.org>
masneyb
parents: 480
diff changeset
1349 multiline = strchr (str, ' ') == NULL;
7334a74db6f6 2004-6-15 Brian Masney <masneyb@gftp.org>
masneyb
parents: 480
diff changeset
1350
107
982e3890e7fe 2003-2-17 Brian Masney <masneyb@gftp.org>
masneyb
parents: 105
diff changeset
1351 *curpos = '\0';
982e3890e7fe 2003-2-17 Brian Masney <masneyb@gftp.org>
masneyb
parents: 105
diff changeset
1352 if (strlen (str) > 4 && strcmp (curpos - 4, ".DIR") == 0)
982e3890e7fe 2003-2-17 Brian Masney <masneyb@gftp.org>
masneyb
parents: 105
diff changeset
1353 {
499
39e9945288ea 2004-7-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 498
diff changeset
1354 fle->st_mode |= S_IFDIR;
107
982e3890e7fe 2003-2-17 Brian Masney <masneyb@gftp.org>
masneyb
parents: 105
diff changeset
1355 *(curpos - 4) = '\0';
982e3890e7fe 2003-2-17 Brian Masney <masneyb@gftp.org>
masneyb
parents: 105
diff changeset
1356 }
982e3890e7fe 2003-2-17 Brian Masney <masneyb@gftp.org>
masneyb
parents: 105
diff changeset
1357
982e3890e7fe 2003-2-17 Brian Masney <masneyb@gftp.org>
masneyb
parents: 105
diff changeset
1358 fle->file = g_strdup (str);
982e3890e7fe 2003-2-17 Brian Masney <masneyb@gftp.org>
masneyb
parents: 105
diff changeset
1359
485
7334a74db6f6 2004-6-15 Brian Masney <masneyb@gftp.org>
masneyb
parents: 480
diff changeset
1360 if (multiline)
7334a74db6f6 2004-6-15 Brian Masney <masneyb@gftp.org>
masneyb
parents: 480
diff changeset
1361 {
7334a74db6f6 2004-6-15 Brian Masney <masneyb@gftp.org>
masneyb
parents: 480
diff changeset
1362 if (request->get_next_dirlist_line == NULL)
7334a74db6f6 2004-6-15 Brian Masney <masneyb@gftp.org>
masneyb
parents: 480
diff changeset
1363 return (GFTP_EFATAL);
7334a74db6f6 2004-6-15 Brian Masney <masneyb@gftp.org>
masneyb
parents: 480
diff changeset
1364
7334a74db6f6 2004-6-15 Brian Masney <masneyb@gftp.org>
masneyb
parents: 480
diff changeset
1365 len = request->get_next_dirlist_line (request, fd, tempstr,
7334a74db6f6 2004-6-15 Brian Masney <masneyb@gftp.org>
masneyb
parents: 480
diff changeset
1366 sizeof (tempstr));
7334a74db6f6 2004-6-15 Brian Masney <masneyb@gftp.org>
masneyb
parents: 480
diff changeset
1367 if (len <= 0)
7334a74db6f6 2004-6-15 Brian Masney <masneyb@gftp.org>
masneyb
parents: 480
diff changeset
1368 return ((int) len);
7334a74db6f6 2004-6-15 Brian Masney <masneyb@gftp.org>
masneyb
parents: 480
diff changeset
1369
7334a74db6f6 2004-6-15 Brian Masney <masneyb@gftp.org>
masneyb
parents: 480
diff changeset
1370 for (curpos = tempstr; *curpos == ' ' || *curpos == '\t'; curpos++);
7334a74db6f6 2004-6-15 Brian Masney <masneyb@gftp.org>
masneyb
parents: 480
diff changeset
1371 }
7334a74db6f6 2004-6-15 Brian Masney <masneyb@gftp.org>
masneyb
parents: 480
diff changeset
1372 else
7334a74db6f6 2004-6-15 Brian Masney <masneyb@gftp.org>
masneyb
parents: 480
diff changeset
1373 curpos = goto_next_token (curpos + 1);
7334a74db6f6 2004-6-15 Brian Masney <masneyb@gftp.org>
masneyb
parents: 480
diff changeset
1374
244
afbbc72b73e2 2003-8-3 Brian Masney <masneyb@gftp.org>
masneyb
parents: 243
diff changeset
1375 fle->size = gftp_parse_file_size (curpos) * 512; /* Is this correct? */
107
982e3890e7fe 2003-2-17 Brian Masney <masneyb@gftp.org>
masneyb
parents: 105
diff changeset
1376
982e3890e7fe 2003-2-17 Brian Masney <masneyb@gftp.org>
masneyb
parents: 105
diff changeset
1377 curpos = goto_next_token (curpos);
982e3890e7fe 2003-2-17 Brian Masney <masneyb@gftp.org>
masneyb
parents: 105
diff changeset
1378
485
7334a74db6f6 2004-6-15 Brian Masney <masneyb@gftp.org>
masneyb
parents: 480
diff changeset
1379 fle->datetime = parse_vms_time (curpos, &curpos);
7334a74db6f6 2004-6-15 Brian Masney <masneyb@gftp.org>
masneyb
parents: 480
diff changeset
1380
107
982e3890e7fe 2003-2-17 Brian Masney <masneyb@gftp.org>
masneyb
parents: 105
diff changeset
1381 if (*curpos != '[')
982e3890e7fe 2003-2-17 Brian Masney <masneyb@gftp.org>
masneyb
parents: 105
diff changeset
1382 return (GFTP_EFATAL);
485
7334a74db6f6 2004-6-15 Brian Masney <masneyb@gftp.org>
masneyb
parents: 480
diff changeset
1383
107
982e3890e7fe 2003-2-17 Brian Masney <masneyb@gftp.org>
masneyb
parents: 105
diff changeset
1384 if ((endpos = strchr (curpos, ']')) == NULL)
982e3890e7fe 2003-2-17 Brian Masney <masneyb@gftp.org>
masneyb
parents: 105
diff changeset
1385 return (GFTP_EFATAL);
982e3890e7fe 2003-2-17 Brian Masney <masneyb@gftp.org>
masneyb
parents: 105
diff changeset
1386
982e3890e7fe 2003-2-17 Brian Masney <masneyb@gftp.org>
masneyb
parents: 105
diff changeset
1387 curpos = goto_next_token (endpos + 1);
982e3890e7fe 2003-2-17 Brian Masney <masneyb@gftp.org>
masneyb
parents: 105
diff changeset
1388 if ((curpos = strchr (curpos, ',')) == NULL)
982e3890e7fe 2003-2-17 Brian Masney <masneyb@gftp.org>
masneyb
parents: 105
diff changeset
1389 return (0);
982e3890e7fe 2003-2-17 Brian Masney <masneyb@gftp.org>
masneyb
parents: 105
diff changeset
1390 curpos++;
982e3890e7fe 2003-2-17 Brian Masney <masneyb@gftp.org>
masneyb
parents: 105
diff changeset
1391
499
39e9945288ea 2004-7-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 498
diff changeset
1392 fle->st_mode = gftp_parse_vms_attribs (&curpos, S_IRWXU);
39e9945288ea 2004-7-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 498
diff changeset
1393 fle->st_mode |= gftp_parse_vms_attribs (&curpos, S_IRWXG);
39e9945288ea 2004-7-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 498
diff changeset
1394 fle->st_mode |= gftp_parse_vms_attribs (&curpos, S_IRWXO);
107
982e3890e7fe 2003-2-17 Brian Masney <masneyb@gftp.org>
masneyb
parents: 105
diff changeset
1395
485
7334a74db6f6 2004-6-15 Brian Masney <masneyb@gftp.org>
masneyb
parents: 480
diff changeset
1396 fle->user = g_strdup ("");
7334a74db6f6 2004-6-15 Brian Masney <masneyb@gftp.org>
masneyb
parents: 480
diff changeset
1397 fle->group = g_strdup ("");
7334a74db6f6 2004-6-15 Brian Masney <masneyb@gftp.org>
masneyb
parents: 480
diff changeset
1398
107
982e3890e7fe 2003-2-17 Brian Masney <masneyb@gftp.org>
masneyb
parents: 105
diff changeset
1399 return (0);
982e3890e7fe 2003-2-17 Brian Masney <masneyb@gftp.org>
masneyb
parents: 105
diff changeset
1400 }
358
28a50fb598ed 2003-1-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 356
diff changeset
1401
28a50fb598ed 2003-1-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 356
diff changeset
1402
28a50fb598ed 2003-1-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 356
diff changeset
1403 static int
28a50fb598ed 2003-1-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 356
diff changeset
1404 gftp_parse_ls_mvs (char *str, gftp_file * fle)
28a50fb598ed 2003-1-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 356
diff changeset
1405 {
28a50fb598ed 2003-1-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 356
diff changeset
1406 char *curpos;
28a50fb598ed 2003-1-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 356
diff changeset
1407
28a50fb598ed 2003-1-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 356
diff changeset
1408 /* Volume Unit Referred Ext Used Recfm Lrecl BlkSz Dsorg Dsname */
28a50fb598ed 2003-1-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 356
diff changeset
1409 /* SVI52A 3390 2003/12/10 8 216 FB 80 27920 PS CARDS.DELETES */
28a50fb598ed 2003-1-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 356
diff changeset
1410 /* SVI528 3390 2003/12/12 1 5 FB 80 24000 PO CLIST */
28a50fb598ed 2003-1-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 356
diff changeset
1411
28a50fb598ed 2003-1-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 356
diff changeset
1412 curpos = goto_next_token (str + 1);
28a50fb598ed 2003-1-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 356
diff changeset
1413 if (curpos == NULL)
28a50fb598ed 2003-1-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 356
diff changeset
1414 return (GFTP_EFATAL);
28a50fb598ed 2003-1-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 356
diff changeset
1415
28a50fb598ed 2003-1-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 356
diff changeset
1416 curpos = goto_next_token (curpos + 1);
28a50fb598ed 2003-1-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 356
diff changeset
1417 if (curpos == NULL)
28a50fb598ed 2003-1-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 356
diff changeset
1418 return (GFTP_EFATAL);
28a50fb598ed 2003-1-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 356
diff changeset
1419
479
11ab311ccb67 2004-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 478
diff changeset
1420 fle->datetime = parse_time (curpos, &curpos);
11ab311ccb67 2004-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 478
diff changeset
1421
11ab311ccb67 2004-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 478
diff changeset
1422 curpos = goto_next_token (curpos);
11ab311ccb67 2004-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 478
diff changeset
1423 if (curpos == NULL)
358
28a50fb598ed 2003-1-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 356
diff changeset
1424 return (GFTP_EFATAL);
28a50fb598ed 2003-1-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 356
diff changeset
1425
28a50fb598ed 2003-1-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 356
diff changeset
1426 curpos = goto_next_token (curpos + 1);
28a50fb598ed 2003-1-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 356
diff changeset
1427 if (curpos == NULL)
28a50fb598ed 2003-1-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 356
diff changeset
1428 return (GFTP_EFATAL);
28a50fb598ed 2003-1-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 356
diff changeset
1429
28a50fb598ed 2003-1-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 356
diff changeset
1430 fle->size = gftp_parse_file_size (curpos) * 55996;
28a50fb598ed 2003-1-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 356
diff changeset
1431 curpos = goto_next_token (curpos + 1);
28a50fb598ed 2003-1-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 356
diff changeset
1432 if (curpos == NULL)
28a50fb598ed 2003-1-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 356
diff changeset
1433 return (GFTP_EFATAL);
28a50fb598ed 2003-1-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 356
diff changeset
1434
28a50fb598ed 2003-1-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 356
diff changeset
1435 curpos = goto_next_token (curpos + 1);
28a50fb598ed 2003-1-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 356
diff changeset
1436 if (curpos == NULL)
28a50fb598ed 2003-1-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 356
diff changeset
1437 return (GFTP_EFATAL);
28a50fb598ed 2003-1-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 356
diff changeset
1438
28a50fb598ed 2003-1-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 356
diff changeset
1439 curpos = goto_next_token (curpos + 1);
28a50fb598ed 2003-1-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 356
diff changeset
1440 if (curpos == NULL)
28a50fb598ed 2003-1-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 356
diff changeset
1441 return (GFTP_EFATAL);
28a50fb598ed 2003-1-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 356
diff changeset
1442
28a50fb598ed 2003-1-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 356
diff changeset
1443 curpos = goto_next_token (curpos + 1);
28a50fb598ed 2003-1-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 356
diff changeset
1444 if (curpos == NULL)
28a50fb598ed 2003-1-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 356
diff changeset
1445 return (GFTP_EFATAL);
28a50fb598ed 2003-1-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 356
diff changeset
1446
28a50fb598ed 2003-1-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 356
diff changeset
1447 if (strncmp (curpos, "PS", 2) == 0)
499
39e9945288ea 2004-7-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 498
diff changeset
1448 fle->st_mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH;
358
28a50fb598ed 2003-1-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 356
diff changeset
1449 else if (strncmp (curpos, "PO", 2) == 0)
499
39e9945288ea 2004-7-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 498
diff changeset
1450 fle->st_mode = S_IFDIR | S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH;
358
28a50fb598ed 2003-1-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 356
diff changeset
1451 else
28a50fb598ed 2003-1-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 356
diff changeset
1452 return (GFTP_EFATAL);
28a50fb598ed 2003-1-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 356
diff changeset
1453
28a50fb598ed 2003-1-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 356
diff changeset
1454 curpos = goto_next_token (curpos + 1);
28a50fb598ed 2003-1-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 356
diff changeset
1455
28a50fb598ed 2003-1-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 356
diff changeset
1456 fle->user = g_strdup (_("unknown"));
28a50fb598ed 2003-1-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 356
diff changeset
1457 fle->group = g_strdup (_("unknown"));
28a50fb598ed 2003-1-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 356
diff changeset
1458 fle->file = g_strdup (curpos);
28a50fb598ed 2003-1-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 356
diff changeset
1459
28a50fb598ed 2003-1-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 356
diff changeset
1460 return (0);
28a50fb598ed 2003-1-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 356
diff changeset
1461 }
107
982e3890e7fe 2003-2-17 Brian Masney <masneyb@gftp.org>
masneyb
parents: 105
diff changeset
1462
982e3890e7fe 2003-2-17 Brian Masney <masneyb@gftp.org>
masneyb
parents: 105
diff changeset
1463
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1464 static int
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1465 gftp_parse_ls_eplf (char *str, gftp_file * fle)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1466 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1467 char *startpos;
358
28a50fb598ed 2003-1-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 356
diff changeset
1468 int isdir = 0;
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1469
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1470 startpos = str;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1471 while (startpos)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1472 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1473 startpos++;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1474 switch (*startpos)
168
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 151
diff changeset
1475 {
516
fbb5a02beddb 2004-7-26 Brian Masney <masneyb@gftp.org>
masneyb
parents: 512
diff changeset
1476 case '/':
fbb5a02beddb 2004-7-26 Brian Masney <masneyb@gftp.org>
masneyb
parents: 512
diff changeset
1477 isdir = 1;
fbb5a02beddb 2004-7-26 Brian Masney <masneyb@gftp.org>
masneyb
parents: 512
diff changeset
1478 break;
fbb5a02beddb 2004-7-26 Brian Masney <masneyb@gftp.org>
masneyb
parents: 512
diff changeset
1479 case 's':
fbb5a02beddb 2004-7-26 Brian Masney <masneyb@gftp.org>
masneyb
parents: 512
diff changeset
1480 fle->size = gftp_parse_file_size (startpos + 1);
fbb5a02beddb 2004-7-26 Brian Masney <masneyb@gftp.org>
masneyb
parents: 512
diff changeset
1481 break;
fbb5a02beddb 2004-7-26 Brian Masney <masneyb@gftp.org>
masneyb
parents: 512
diff changeset
1482 case 'm':
fbb5a02beddb 2004-7-26 Brian Masney <masneyb@gftp.org>
masneyb
parents: 512
diff changeset
1483 fle->datetime = strtol (startpos + 1, NULL, 10);
fbb5a02beddb 2004-7-26 Brian Masney <masneyb@gftp.org>
masneyb
parents: 512
diff changeset
1484 break;
168
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 151
diff changeset
1485 }
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1486 startpos = strchr (startpos, ',');
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1487 }
358
28a50fb598ed 2003-1-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 356
diff changeset
1488
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1489 if ((startpos = strchr (str, 9)) == NULL)
84
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 76
diff changeset
1490 return (GFTP_EFATAL);
358
28a50fb598ed 2003-1-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 356
diff changeset
1491
28a50fb598ed 2003-1-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 356
diff changeset
1492 if (isdir)
499
39e9945288ea 2004-7-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 498
diff changeset
1493 fle->st_mode = S_IFDIR | S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH;
358
28a50fb598ed 2003-1-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 356
diff changeset
1494 else
499
39e9945288ea 2004-7-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 498
diff changeset
1495 fle->st_mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH;
358
28a50fb598ed 2003-1-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 356
diff changeset
1496
124
65048c959029 2003-4-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 122
diff changeset
1497 fle->file = g_strdup (startpos + 1);
65048c959029 2003-4-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 122
diff changeset
1498 fle->user = g_strdup (_("unknown"));
65048c959029 2003-4-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 122
diff changeset
1499 fle->group = g_strdup (_("unknown"));
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1500 return (0);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1501 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1502
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1503
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1504 static int
460
075f89b4395c 2004-4-14 Brian Masney <masneyb@gftp.org>
masneyb
parents: 451
diff changeset
1505 gftp_parse_ls_unix (gftp_request * request, char *str, size_t slen,
075f89b4395c 2004-4-14 Brian Masney <masneyb@gftp.org>
masneyb
parents: 451
diff changeset
1506 gftp_file * fle)
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1507 {
499
39e9945288ea 2004-7-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 498
diff changeset
1508 char *endpos, *startpos, *pos, *attribs;
91
8c37d73d3f1f 2003-1-21 Brian Masney <masneyb@gftp.org>
masneyb
parents: 87
diff changeset
1509 int cols;
8c37d73d3f1f 2003-1-21 Brian Masney <masneyb@gftp.org>
masneyb
parents: 87
diff changeset
1510
8c37d73d3f1f 2003-1-21 Brian Masney <masneyb@gftp.org>
masneyb
parents: 87
diff changeset
1511 /* If there is no space between the attribs and links field, just make one */
460
075f89b4395c 2004-4-14 Brian Masney <masneyb@gftp.org>
masneyb
parents: 451
diff changeset
1512 if (slen > 10)
91
8c37d73d3f1f 2003-1-21 Brian Masney <masneyb@gftp.org>
masneyb
parents: 87
diff changeset
1513 str[10] = ' ';
8c37d73d3f1f 2003-1-21 Brian Masney <masneyb@gftp.org>
masneyb
parents: 87
diff changeset
1514
8c37d73d3f1f 2003-1-21 Brian Masney <masneyb@gftp.org>
masneyb
parents: 87
diff changeset
1515 /* Determine the number of columns */
8c37d73d3f1f 2003-1-21 Brian Masney <masneyb@gftp.org>
masneyb
parents: 87
diff changeset
1516 cols = 0;
8c37d73d3f1f 2003-1-21 Brian Masney <masneyb@gftp.org>
masneyb
parents: 87
diff changeset
1517 pos = str;
8c37d73d3f1f 2003-1-21 Brian Masney <masneyb@gftp.org>
masneyb
parents: 87
diff changeset
1518 while (*pos != '\0')
8c37d73d3f1f 2003-1-21 Brian Masney <masneyb@gftp.org>
masneyb
parents: 87
diff changeset
1519 {
8c37d73d3f1f 2003-1-21 Brian Masney <masneyb@gftp.org>
masneyb
parents: 87
diff changeset
1520 while (*pos != '\0' && *pos != ' ' && *pos != '\t')
8c37d73d3f1f 2003-1-21 Brian Masney <masneyb@gftp.org>
masneyb
parents: 87
diff changeset
1521 {
8c37d73d3f1f 2003-1-21 Brian Masney <masneyb@gftp.org>
masneyb
parents: 87
diff changeset
1522 if (*pos == ':')
8c37d73d3f1f 2003-1-21 Brian Masney <masneyb@gftp.org>
masneyb
parents: 87
diff changeset
1523 break;
8c37d73d3f1f 2003-1-21 Brian Masney <masneyb@gftp.org>
masneyb
parents: 87
diff changeset
1524 pos++;
8c37d73d3f1f 2003-1-21 Brian Masney <masneyb@gftp.org>
masneyb
parents: 87
diff changeset
1525 }
8c37d73d3f1f 2003-1-21 Brian Masney <masneyb@gftp.org>
masneyb
parents: 87
diff changeset
1526
8c37d73d3f1f 2003-1-21 Brian Masney <masneyb@gftp.org>
masneyb
parents: 87
diff changeset
1527 cols++;
8c37d73d3f1f 2003-1-21 Brian Masney <masneyb@gftp.org>
masneyb
parents: 87
diff changeset
1528
8c37d73d3f1f 2003-1-21 Brian Masney <masneyb@gftp.org>
masneyb
parents: 87
diff changeset
1529 if (*pos == ':')
8c37d73d3f1f 2003-1-21 Brian Masney <masneyb@gftp.org>
masneyb
parents: 87
diff changeset
1530 {
8c37d73d3f1f 2003-1-21 Brian Masney <masneyb@gftp.org>
masneyb
parents: 87
diff changeset
1531 cols++;
8c37d73d3f1f 2003-1-21 Brian Masney <masneyb@gftp.org>
masneyb
parents: 87
diff changeset
1532 break;
8c37d73d3f1f 2003-1-21 Brian Masney <masneyb@gftp.org>
masneyb
parents: 87
diff changeset
1533 }
8c37d73d3f1f 2003-1-21 Brian Masney <masneyb@gftp.org>
masneyb
parents: 87
diff changeset
1534
8c37d73d3f1f 2003-1-21 Brian Masney <masneyb@gftp.org>
masneyb
parents: 87
diff changeset
1535 while (*pos == ' ' || *pos == '\t')
8c37d73d3f1f 2003-1-21 Brian Masney <masneyb@gftp.org>
masneyb
parents: 87
diff changeset
1536 pos++;
8c37d73d3f1f 2003-1-21 Brian Masney <masneyb@gftp.org>
masneyb
parents: 87
diff changeset
1537 }
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1538
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1539 startpos = str;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1540 /* Copy file attributes */
499
39e9945288ea 2004-7-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 498
diff changeset
1541 if ((startpos = copy_token (&attribs, startpos)) == NULL)
84
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 76
diff changeset
1542 return (GFTP_EFATAL);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1543
499
39e9945288ea 2004-7-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 498
diff changeset
1544 fle->st_mode = gftp_convert_attributes_to_mode_t (attribs);
39e9945288ea 2004-7-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 498
diff changeset
1545 g_free (attribs);
39e9945288ea 2004-7-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 498
diff changeset
1546
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1547 if (cols >= 9)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1548 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1549 /* Skip the number of links */
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1550 startpos = goto_next_token (startpos);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1551
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1552 /* Copy the user that owns this file */
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1553 if ((startpos = copy_token (&fle->user, startpos)) == NULL)
168
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 151
diff changeset
1554 return (GFTP_EFATAL);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1555
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1556 /* Copy the group that owns this file */
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1557 if ((startpos = copy_token (&fle->group, startpos)) == NULL)
168
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 151
diff changeset
1558 return (GFTP_EFATAL);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1559 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1560 else
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1561 {
124
65048c959029 2003-4-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 122
diff changeset
1562 fle->group = g_strdup (_("unknown"));
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1563 if (cols == 8)
168
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 151
diff changeset
1564 {
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 151
diff changeset
1565 if ((startpos = copy_token (&fle->user, startpos)) == NULL)
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 151
diff changeset
1566 return (GFTP_EFATAL);
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 151
diff changeset
1567 }
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1568 else
124
65048c959029 2003-4-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 122
diff changeset
1569 fle->user = g_strdup (_("unknown"));
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1570 startpos = goto_next_token (startpos);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1571 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1572
281
1c7cde8a3a53 2003-10-4 Brian Masney <masneyb@gftp.org>
masneyb
parents: 275
diff changeset
1573 if (request->server_type == GFTP_DIRTYPE_CRAY)
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1574 {
91
8c37d73d3f1f 2003-1-21 Brian Masney <masneyb@gftp.org>
masneyb
parents: 87
diff changeset
1575 /* See if this is a Cray directory listing. It has the following format:
8c37d73d3f1f 2003-1-21 Brian Masney <masneyb@gftp.org>
masneyb
parents: 87
diff changeset
1576 drwx------ 2 feiliu g913 DK common 4096 Sep 24 2001 wv */
8c37d73d3f1f 2003-1-21 Brian Masney <masneyb@gftp.org>
masneyb
parents: 87
diff changeset
1577 if (cols == 11 && strstr (str, "->") == NULL)
8c37d73d3f1f 2003-1-21 Brian Masney <masneyb@gftp.org>
masneyb
parents: 87
diff changeset
1578 {
8c37d73d3f1f 2003-1-21 Brian Masney <masneyb@gftp.org>
masneyb
parents: 87
diff changeset
1579 startpos = goto_next_token (startpos);
8c37d73d3f1f 2003-1-21 Brian Masney <masneyb@gftp.org>
masneyb
parents: 87
diff changeset
1580 startpos = goto_next_token (startpos);
8c37d73d3f1f 2003-1-21 Brian Masney <masneyb@gftp.org>
masneyb
parents: 87
diff changeset
1581 }
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1582 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1583
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1584 /* See if this is a block or character device. We will store the major number
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1585 in the high word and the minor number in the low word. */
499
39e9945288ea 2004-7-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 498
diff changeset
1586 if (GFTP_IS_SPECIAL_DEVICE (fle->st_mode) &&
39e9945288ea 2004-7-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 498
diff changeset
1587 (endpos = strchr (startpos, ',')) != NULL)
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1588 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1589 fle->size = strtol (startpos, NULL, 10) << 16;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1590
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1591 startpos = endpos + 1;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1592 while (*startpos == ' ')
168
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 151
diff changeset
1593 startpos++;
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1594
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1595 /* Get the minor number */
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1596 if ((endpos = strchr (startpos, ' ')) == NULL)
168
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 151
diff changeset
1597 return (GFTP_EFATAL);
14
83090328581e * More largefile support. Hopefully all that is left is the configure stuff
masneyb
parents: 7
diff changeset
1598 fle->size |= strtol (startpos, NULL, 10) & 0xFF;
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1599 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1600 else
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1601 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1602 /* This is a regular file */
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1603 if ((endpos = strchr (startpos, ' ')) == NULL)
168
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 151
diff changeset
1604 return (GFTP_EFATAL);
244
afbbc72b73e2 2003-8-3 Brian Masney <masneyb@gftp.org>
masneyb
parents: 243
diff changeset
1605 fle->size = gftp_parse_file_size (startpos);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1606 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1607
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1608 /* Skip the blanks till we get to the next entry */
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1609 startpos = endpos + 1;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1610 while (*startpos == ' ')
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1611 startpos++;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1612
479
11ab311ccb67 2004-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 478
diff changeset
1613 fle->datetime = parse_time (startpos, &startpos);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1614
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1615 /* Skip the blanks till we get to the next entry */
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1616 startpos = goto_next_token (startpos);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1617
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1618 /* Parse the filename. If this file is a symbolic link, remove the -> part */
499
39e9945288ea 2004-7-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 498
diff changeset
1619 if (S_ISLNK (fle->st_mode) && ((endpos = strstr (startpos, "->")) != NULL))
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1620 *(endpos - 1) = '\0';
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1621
124
65048c959029 2003-4-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 122
diff changeset
1622 fle->file = g_strdup (startpos);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1623
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1624 /* Uncomment this if you want to strip the spaces off of the end of the file.
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1625 I don't want to do this by default since there are valid filenames with
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1626 spaces at the end of them. Some broken FTP servers like the Paradyne IPC
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1627 DSLAMS append a bunch of spaces at the end of the file.
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1628 for (endpos = fle->file + strlen (fle->file) - 1;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1629 *endpos == ' ';
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1630 *endpos-- = '\0');
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1631 */
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1632
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1633 return (0);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1634 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1635
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1636
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1637 static int
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1638 gftp_parse_ls_nt (char *str, gftp_file * fle)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1639 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1640 char *startpos;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1641
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1642 startpos = str;
479
11ab311ccb67 2004-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 478
diff changeset
1643 fle->datetime = parse_time (startpos, &startpos);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1644
124
65048c959029 2003-4-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 122
diff changeset
1645 fle->user = g_strdup (_("unknown"));
65048c959029 2003-4-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 122
diff changeset
1646 fle->group = g_strdup (_("unknown"));
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1647
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1648 startpos = goto_next_token (startpos);
499
39e9945288ea 2004-7-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 498
diff changeset
1649
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1650 if (startpos[0] == '<')
499
39e9945288ea 2004-7-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 498
diff changeset
1651 fle->st_mode = S_IFDIR | S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH;
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1652 else
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1653 {
499
39e9945288ea 2004-7-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 498
diff changeset
1654 fle->st_mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH;
244
afbbc72b73e2 2003-8-3 Brian Masney <masneyb@gftp.org>
masneyb
parents: 243
diff changeset
1655 fle->size = gftp_parse_file_size (startpos);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1656 }
124
65048c959029 2003-4-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 122
diff changeset
1657
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1658 startpos = goto_next_token (startpos);
124
65048c959029 2003-4-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 122
diff changeset
1659 fle->file = g_strdup (startpos);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1660 return (0);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1661 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1662
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1663
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1664 static int
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1665 gftp_parse_ls_novell (char *str, gftp_file * fle)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1666 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1667 char *startpos;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1668
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1669 if (str[12] != ' ')
84
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 76
diff changeset
1670 return (GFTP_EFATAL);
499
39e9945288ea 2004-7-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 498
diff changeset
1671
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1672 str[12] = '\0';
499
39e9945288ea 2004-7-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 498
diff changeset
1673 fle->st_mode = gftp_convert_attributes_to_mode_t (str);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1674 startpos = str + 13;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1675
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1676 while ((*startpos == ' ' || *startpos == '\t') && *startpos != '\0')
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1677 startpos++;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1678
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1679 if ((startpos = copy_token (&fle->user, startpos)) == NULL)
84
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 76
diff changeset
1680 return (GFTP_EFATAL);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1681
124
65048c959029 2003-4-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 122
diff changeset
1682 fle->group = g_strdup (_("unknown"));
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1683
244
afbbc72b73e2 2003-8-3 Brian Masney <masneyb@gftp.org>
masneyb
parents: 243
diff changeset
1684 fle->size = gftp_parse_file_size (startpos);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1685
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1686 startpos = goto_next_token (startpos);
479
11ab311ccb67 2004-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 478
diff changeset
1687 fle->datetime = parse_time (startpos, &startpos);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1688
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1689 startpos = goto_next_token (startpos);
124
65048c959029 2003-4-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 122
diff changeset
1690 fle->file = g_strdup (startpos);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1691 return (0);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1692 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1693
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1694
48
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 46
diff changeset
1695 int
485
7334a74db6f6 2004-6-15 Brian Masney <masneyb@gftp.org>
masneyb
parents: 480
diff changeset
1696 gftp_parse_ls (gftp_request * request, const char *lsoutput, gftp_file * fle,
7334a74db6f6 2004-6-15 Brian Masney <masneyb@gftp.org>
masneyb
parents: 480
diff changeset
1697 int fd)
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1698 {
107
982e3890e7fe 2003-2-17 Brian Masney <masneyb@gftp.org>
masneyb
parents: 105
diff changeset
1699 char *str, *endpos, tmpchar;
982e3890e7fe 2003-2-17 Brian Masney <masneyb@gftp.org>
masneyb
parents: 105
diff changeset
1700 int result, is_vms;
91
8c37d73d3f1f 2003-1-21 Brian Masney <masneyb@gftp.org>
masneyb
parents: 87
diff changeset
1701 size_t len;
48
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 46
diff changeset
1702
84
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 76
diff changeset
1703 g_return_val_if_fail (lsoutput != NULL, GFTP_EFATAL);
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 76
diff changeset
1704 g_return_val_if_fail (fle != NULL, GFTP_EFATAL);
48
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 46
diff changeset
1705
124
65048c959029 2003-4-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 122
diff changeset
1706 str = g_strdup (lsoutput);
48
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 46
diff changeset
1707 memset (fle, 0, sizeof (*fle));
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1708
91
8c37d73d3f1f 2003-1-21 Brian Masney <masneyb@gftp.org>
masneyb
parents: 87
diff changeset
1709 len = strlen (str);
107
982e3890e7fe 2003-2-17 Brian Masney <masneyb@gftp.org>
masneyb
parents: 105
diff changeset
1710 if (len > 0 && str[len - 1] == '\n')
91
8c37d73d3f1f 2003-1-21 Brian Masney <masneyb@gftp.org>
masneyb
parents: 87
diff changeset
1711 str[--len] = '\0';
8c37d73d3f1f 2003-1-21 Brian Masney <masneyb@gftp.org>
masneyb
parents: 87
diff changeset
1712 if (len > 0 && str[len - 1] == '\r')
8c37d73d3f1f 2003-1-21 Brian Masney <masneyb@gftp.org>
masneyb
parents: 87
diff changeset
1713 str[--len] = '\0';
39
474d562c7268 2002-10-15 Brian Masney <masneyb@gftp.org>
masneyb
parents: 33
diff changeset
1714
91
8c37d73d3f1f 2003-1-21 Brian Masney <masneyb@gftp.org>
masneyb
parents: 87
diff changeset
1715 switch (request->server_type)
8c37d73d3f1f 2003-1-21 Brian Masney <masneyb@gftp.org>
masneyb
parents: 87
diff changeset
1716 {
122
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 107
diff changeset
1717 case GFTP_DIRTYPE_CRAY:
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 107
diff changeset
1718 case GFTP_DIRTYPE_UNIX:
460
075f89b4395c 2004-4-14 Brian Masney <masneyb@gftp.org>
masneyb
parents: 451
diff changeset
1719 result = gftp_parse_ls_unix (request, str, len, fle);
91
8c37d73d3f1f 2003-1-21 Brian Masney <masneyb@gftp.org>
masneyb
parents: 87
diff changeset
1720 break;
122
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 107
diff changeset
1721 case GFTP_DIRTYPE_EPLF:
91
8c37d73d3f1f 2003-1-21 Brian Masney <masneyb@gftp.org>
masneyb
parents: 87
diff changeset
1722 result = gftp_parse_ls_eplf (str, fle);
8c37d73d3f1f 2003-1-21 Brian Masney <masneyb@gftp.org>
masneyb
parents: 87
diff changeset
1723 break;
122
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 107
diff changeset
1724 case GFTP_DIRTYPE_NOVELL:
91
8c37d73d3f1f 2003-1-21 Brian Masney <masneyb@gftp.org>
masneyb
parents: 87
diff changeset
1725 result = gftp_parse_ls_novell (str, fle);
8c37d73d3f1f 2003-1-21 Brian Masney <masneyb@gftp.org>
masneyb
parents: 87
diff changeset
1726 break;
122
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 107
diff changeset
1727 case GFTP_DIRTYPE_DOS:
91
8c37d73d3f1f 2003-1-21 Brian Masney <masneyb@gftp.org>
masneyb
parents: 87
diff changeset
1728 result = gftp_parse_ls_nt (str, fle);
8c37d73d3f1f 2003-1-21 Brian Masney <masneyb@gftp.org>
masneyb
parents: 87
diff changeset
1729 break;
122
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 107
diff changeset
1730 case GFTP_DIRTYPE_VMS:
485
7334a74db6f6 2004-6-15 Brian Masney <masneyb@gftp.org>
masneyb
parents: 480
diff changeset
1731 result = gftp_parse_ls_vms (request, fd, str, fle);
107
982e3890e7fe 2003-2-17 Brian Masney <masneyb@gftp.org>
masneyb
parents: 105
diff changeset
1732 break;
358
28a50fb598ed 2003-1-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 356
diff changeset
1733 case GFTP_DIRTYPE_MVS:
28a50fb598ed 2003-1-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 356
diff changeset
1734 result = gftp_parse_ls_mvs (str, fle);
28a50fb598ed 2003-1-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 356
diff changeset
1735 break;
91
8c37d73d3f1f 2003-1-21 Brian Masney <masneyb@gftp.org>
masneyb
parents: 87
diff changeset
1736 default: /* autodetect */
8c37d73d3f1f 2003-1-21 Brian Masney <masneyb@gftp.org>
masneyb
parents: 87
diff changeset
1737 if (*lsoutput == '+')
8c37d73d3f1f 2003-1-21 Brian Masney <masneyb@gftp.org>
masneyb
parents: 87
diff changeset
1738 result = gftp_parse_ls_eplf (str, fle);
8c37d73d3f1f 2003-1-21 Brian Masney <masneyb@gftp.org>
masneyb
parents: 87
diff changeset
1739 else if (isdigit ((int) str[0]) && str[2] == '-')
8c37d73d3f1f 2003-1-21 Brian Masney <masneyb@gftp.org>
masneyb
parents: 87
diff changeset
1740 result = gftp_parse_ls_nt (str, fle);
8c37d73d3f1f 2003-1-21 Brian Masney <masneyb@gftp.org>
masneyb
parents: 87
diff changeset
1741 else if (str[1] == ' ' && str[2] == '[')
8c37d73d3f1f 2003-1-21 Brian Masney <masneyb@gftp.org>
masneyb
parents: 87
diff changeset
1742 result = gftp_parse_ls_novell (str, fle);
8c37d73d3f1f 2003-1-21 Brian Masney <masneyb@gftp.org>
masneyb
parents: 87
diff changeset
1743 else
107
982e3890e7fe 2003-2-17 Brian Masney <masneyb@gftp.org>
masneyb
parents: 105
diff changeset
1744 {
982e3890e7fe 2003-2-17 Brian Masney <masneyb@gftp.org>
masneyb
parents: 105
diff changeset
1745 if ((endpos = strchr (str, ' ')) != NULL)
982e3890e7fe 2003-2-17 Brian Masney <masneyb@gftp.org>
masneyb
parents: 105
diff changeset
1746 {
982e3890e7fe 2003-2-17 Brian Masney <masneyb@gftp.org>
masneyb
parents: 105
diff changeset
1747 /* If the first token in the string has a ; in it, then */
982e3890e7fe 2003-2-17 Brian Masney <masneyb@gftp.org>
masneyb
parents: 105
diff changeset
1748 /* we'll assume that this is a VMS directory listing */
982e3890e7fe 2003-2-17 Brian Masney <masneyb@gftp.org>
masneyb
parents: 105
diff changeset
1749 tmpchar = *endpos;
982e3890e7fe 2003-2-17 Brian Masney <masneyb@gftp.org>
masneyb
parents: 105
diff changeset
1750 *endpos = '\0';
982e3890e7fe 2003-2-17 Brian Masney <masneyb@gftp.org>
masneyb
parents: 105
diff changeset
1751 is_vms = strchr (str, ';') != NULL;
982e3890e7fe 2003-2-17 Brian Masney <masneyb@gftp.org>
masneyb
parents: 105
diff changeset
1752 *endpos = tmpchar;
982e3890e7fe 2003-2-17 Brian Masney <masneyb@gftp.org>
masneyb
parents: 105
diff changeset
1753 }
982e3890e7fe 2003-2-17 Brian Masney <masneyb@gftp.org>
masneyb
parents: 105
diff changeset
1754 else
982e3890e7fe 2003-2-17 Brian Masney <masneyb@gftp.org>
masneyb
parents: 105
diff changeset
1755 is_vms = 0;
48
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 46
diff changeset
1756
107
982e3890e7fe 2003-2-17 Brian Masney <masneyb@gftp.org>
masneyb
parents: 105
diff changeset
1757 if (is_vms)
485
7334a74db6f6 2004-6-15 Brian Masney <masneyb@gftp.org>
masneyb
parents: 480
diff changeset
1758 result = gftp_parse_ls_vms (request, fd, str, fle);
107
982e3890e7fe 2003-2-17 Brian Masney <masneyb@gftp.org>
masneyb
parents: 105
diff changeset
1759 else
460
075f89b4395c 2004-4-14 Brian Masney <masneyb@gftp.org>
masneyb
parents: 451
diff changeset
1760 result = gftp_parse_ls_unix (request, str, len, fle);
107
982e3890e7fe 2003-2-17 Brian Masney <masneyb@gftp.org>
masneyb
parents: 105
diff changeset
1761 }
91
8c37d73d3f1f 2003-1-21 Brian Masney <masneyb@gftp.org>
masneyb
parents: 87
diff changeset
1762 break;
48
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 46
diff changeset
1763 }
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 46
diff changeset
1764 g_free (str);
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 46
diff changeset
1765
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 46
diff changeset
1766 return (result);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1767 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1768
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1769
48
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 46
diff changeset
1770 static GHashTable *
469
2ad1916dc611 2004-5-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 463
diff changeset
1771 gftp_gen_dir_hash (gftp_request * request, int *ret)
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1772 {
48
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 46
diff changeset
1773 GHashTable * dirhash;
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 46
diff changeset
1774 gftp_file * fle;
516
fbb5a02beddb 2004-7-26 Brian Masney <masneyb@gftp.org>
masneyb
parents: 512
diff changeset
1775 off_t *newsize;
48
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 46
diff changeset
1776 char * newname;
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 46
diff changeset
1777
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 46
diff changeset
1778 dirhash = g_hash_table_new (string_hash_function, string_hash_compare);
469
2ad1916dc611 2004-5-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 463
diff changeset
1779 *ret = gftp_list_files (request);
2ad1916dc611 2004-5-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 463
diff changeset
1780 if (*ret == 0)
48
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 46
diff changeset
1781 {
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 46
diff changeset
1782 fle = g_malloc0 (sizeof (*fle));
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 46
diff changeset
1783 while (gftp_get_next_file (request, NULL, fle) > 0)
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 46
diff changeset
1784 {
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 46
diff changeset
1785 newname = fle->file;
516
fbb5a02beddb 2004-7-26 Brian Masney <masneyb@gftp.org>
masneyb
parents: 512
diff changeset
1786 newsize = g_malloc (sizeof (*newsize));
48
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 46
diff changeset
1787 *newsize = fle->size;
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 46
diff changeset
1788 g_hash_table_insert (dirhash, newname, newsize);
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 46
diff changeset
1789 fle->file = NULL;
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 46
diff changeset
1790 gftp_file_destroy (fle);
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 46
diff changeset
1791 }
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 46
diff changeset
1792 gftp_end_transfer (request);
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 46
diff changeset
1793 g_free (fle);
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 46
diff changeset
1794 }
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 46
diff changeset
1795 else
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 46
diff changeset
1796 {
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 46
diff changeset
1797 g_hash_table_destroy (dirhash);
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 46
diff changeset
1798 dirhash = NULL;
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 46
diff changeset
1799 }
509
b6ce74de1cd9 2004-7-24 Brian Masney <masneyb@gftp.org>
masneyb
parents: 504
diff changeset
1800
48
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 46
diff changeset
1801 return (dirhash);
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 46
diff changeset
1802 }
39
474d562c7268 2002-10-15 Brian Masney <masneyb@gftp.org>
masneyb
parents: 33
diff changeset
1803
48
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 46
diff changeset
1804
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 46
diff changeset
1805 static void
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 46
diff changeset
1806 destroy_hash_ent (gpointer key, gpointer value, gpointer user_data)
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 46
diff changeset
1807 {
39
474d562c7268 2002-10-15 Brian Masney <masneyb@gftp.org>
masneyb
parents: 33
diff changeset
1808
48
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 46
diff changeset
1809 g_free (key);
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 46
diff changeset
1810 g_free (value);
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 46
diff changeset
1811 }
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 46
diff changeset
1812
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 46
diff changeset
1813
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 46
diff changeset
1814 static void
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 46
diff changeset
1815 gftp_destroy_dir_hash (GHashTable * dirhash)
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 46
diff changeset
1816 {
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 46
diff changeset
1817 g_hash_table_foreach (dirhash, destroy_hash_ent, NULL);
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 46
diff changeset
1818 g_hash_table_destroy (dirhash);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1819 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1820
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1821
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1822 static GList *
469
2ad1916dc611 2004-5-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 463
diff changeset
1823 gftp_get_dir_listing (gftp_transfer * transfer, int getothdir, int *ret)
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1824 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1825 GHashTable * dirhash;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1826 GList * templist;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1827 gftp_file * fle;
516
fbb5a02beddb 2004-7-26 Brian Masney <masneyb@gftp.org>
masneyb
parents: 512
diff changeset
1828 off_t *newsize;
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1829 char *newname;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1830
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1831 if (getothdir && transfer->toreq)
469
2ad1916dc611 2004-5-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 463
diff changeset
1832 {
2ad1916dc611 2004-5-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 463
diff changeset
1833 dirhash = gftp_gen_dir_hash (transfer->toreq, ret);
2ad1916dc611 2004-5-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 463
diff changeset
1834 if (*ret < 0)
2ad1916dc611 2004-5-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 463
diff changeset
1835 return (NULL);
2ad1916dc611 2004-5-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 463
diff changeset
1836 }
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1837 else
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1838 dirhash = NULL;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1839
509
b6ce74de1cd9 2004-7-24 Brian Masney <masneyb@gftp.org>
masneyb
parents: 504
diff changeset
1840 *ret = gftp_list_files (transfer->fromreq);
b6ce74de1cd9 2004-7-24 Brian Masney <masneyb@gftp.org>
masneyb
parents: 504
diff changeset
1841 if (*ret < 0)
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1842 return (NULL);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1843
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1844 fle = g_malloc (sizeof (*fle));
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1845 templist = NULL;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1846 while (gftp_get_next_file (transfer->fromreq, NULL, fle) > 0)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1847 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1848 if (strcmp (fle->file, ".") == 0 || strcmp (fle->file, "..") == 0)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1849 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1850 gftp_file_destroy (fle);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1851 continue;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1852 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1853
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1854 if (dirhash &&
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1855 (newsize = g_hash_table_lookup (dirhash, fle->file)) != NULL)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1856 fle->startsize = *newsize;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1857
381
1c86bcb0b232 2003-2-1 Brian Masney <masneyb@gftp.org>
masneyb
parents: 377
diff changeset
1858 if (transfer->toreq && fle->destfile == NULL)
245
41af60bc1f88 2003-8-4 Brian Masney <masneyb@gftp.org>
masneyb
parents: 244
diff changeset
1859 fle->destfile = gftp_build_path (transfer->toreq->directory,
41af60bc1f88 2003-8-4 Brian Masney <masneyb@gftp.org>
masneyb
parents: 244
diff changeset
1860 fle->file, NULL);
41af60bc1f88 2003-8-4 Brian Masney <masneyb@gftp.org>
masneyb
parents: 244
diff changeset
1861
381
1c86bcb0b232 2003-2-1 Brian Masney <masneyb@gftp.org>
masneyb
parents: 377
diff changeset
1862 if (transfer->fromreq->directory != NULL &&
1c86bcb0b232 2003-2-1 Brian Masney <masneyb@gftp.org>
masneyb
parents: 377
diff changeset
1863 *transfer->fromreq->directory != '\0' &&
1c86bcb0b232 2003-2-1 Brian Masney <masneyb@gftp.org>
masneyb
parents: 377
diff changeset
1864 *fle->file != '/')
1c86bcb0b232 2003-2-1 Brian Masney <masneyb@gftp.org>
masneyb
parents: 377
diff changeset
1865 {
1c86bcb0b232 2003-2-1 Brian Masney <masneyb@gftp.org>
masneyb
parents: 377
diff changeset
1866 newname = gftp_build_path (transfer->fromreq->directory,
1c86bcb0b232 2003-2-1 Brian Masney <masneyb@gftp.org>
masneyb
parents: 377
diff changeset
1867 fle->file, NULL);
1c86bcb0b232 2003-2-1 Brian Masney <masneyb@gftp.org>
masneyb
parents: 377
diff changeset
1868
1c86bcb0b232 2003-2-1 Brian Masney <masneyb@gftp.org>
masneyb
parents: 377
diff changeset
1869 g_free (fle->file);
1c86bcb0b232 2003-2-1 Brian Masney <masneyb@gftp.org>
masneyb
parents: 377
diff changeset
1870 fle->file = newname;
1c86bcb0b232 2003-2-1 Brian Masney <masneyb@gftp.org>
masneyb
parents: 377
diff changeset
1871 }
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1872
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1873 templist = g_list_append (templist, fle);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1874
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1875 fle = g_malloc (sizeof (*fle));
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1876 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1877 gftp_end_transfer (transfer->fromreq);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1878
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1879 gftp_file_destroy (fle);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1880 g_free (fle);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1881
509
b6ce74de1cd9 2004-7-24 Brian Masney <masneyb@gftp.org>
masneyb
parents: 504
diff changeset
1882 if (dirhash != NULL)
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1883 gftp_destroy_dir_hash (dirhash);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1884
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1885 return (templist);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1886 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1887
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1888
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1889 int
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1890 gftp_get_all_subdirs (gftp_transfer * transfer,
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1891 void (*update_func) (gftp_transfer * transfer))
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1892 {
381
1c86bcb0b232 2003-2-1 Brian Masney <masneyb@gftp.org>
masneyb
parents: 377
diff changeset
1893 char *oldfromdir, *oldtodir, *newname, *pos;
469
2ad1916dc611 2004-5-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 463
diff changeset
1894 int forcecd, remotechanged, ret;
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1895 GList * templist, * lastlist;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1896 GHashTable * dirhash;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1897 gftp_file * curfle;
516
fbb5a02beddb 2004-7-26 Brian Masney <masneyb@gftp.org>
masneyb
parents: 512
diff changeset
1898 off_t *newsize;
500
ba50a7085d93 2004-7-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 499
diff changeset
1899 mode_t st_mode;
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1900
84
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 76
diff changeset
1901 g_return_val_if_fail (transfer != NULL, GFTP_EFATAL);
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 76
diff changeset
1902 g_return_val_if_fail (transfer->fromreq != NULL, GFTP_EFATAL);
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 76
diff changeset
1903 g_return_val_if_fail (transfer->files != NULL, GFTP_EFATAL);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1904
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1905 if (transfer->toreq != NULL)
469
2ad1916dc611 2004-5-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 463
diff changeset
1906 {
2ad1916dc611 2004-5-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 463
diff changeset
1907 ret = 0;
2ad1916dc611 2004-5-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 463
diff changeset
1908 dirhash = gftp_gen_dir_hash (transfer->toreq, &ret);
2ad1916dc611 2004-5-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 463
diff changeset
1909 if (ret < 0)
2ad1916dc611 2004-5-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 463
diff changeset
1910 return (ret);
2ad1916dc611 2004-5-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 463
diff changeset
1911 }
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1912 else
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1913 dirhash = NULL;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1914
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1915 for (lastlist = transfer->files; ; lastlist = lastlist->next)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1916 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1917 curfle = lastlist->data;
381
1c86bcb0b232 2003-2-1 Brian Masney <masneyb@gftp.org>
masneyb
parents: 377
diff changeset
1918
1c86bcb0b232 2003-2-1 Brian Masney <masneyb@gftp.org>
masneyb
parents: 377
diff changeset
1919 if ((pos = strrchr (curfle->file, '/')) != NULL)
1c86bcb0b232 2003-2-1 Brian Masney <masneyb@gftp.org>
masneyb
parents: 377
diff changeset
1920 pos++;
1c86bcb0b232 2003-2-1 Brian Masney <masneyb@gftp.org>
masneyb
parents: 377
diff changeset
1921 else
1c86bcb0b232 2003-2-1 Brian Masney <masneyb@gftp.org>
masneyb
parents: 377
diff changeset
1922 pos = curfle->file;
1c86bcb0b232 2003-2-1 Brian Masney <masneyb@gftp.org>
masneyb
parents: 377
diff changeset
1923
1c86bcb0b232 2003-2-1 Brian Masney <masneyb@gftp.org>
masneyb
parents: 377
diff changeset
1924 if (dirhash != NULL &&
1c86bcb0b232 2003-2-1 Brian Masney <masneyb@gftp.org>
masneyb
parents: 377
diff changeset
1925 (newsize = g_hash_table_lookup (dirhash, pos)) != NULL)
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1926 curfle->startsize = *newsize;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1927
381
1c86bcb0b232 2003-2-1 Brian Masney <masneyb@gftp.org>
masneyb
parents: 377
diff changeset
1928 if (curfle->size < 0 && GFTP_IS_CONNECTED (transfer->fromreq))
509
b6ce74de1cd9 2004-7-24 Brian Masney <masneyb@gftp.org>
masneyb
parents: 504
diff changeset
1929 {
b6ce74de1cd9 2004-7-24 Brian Masney <masneyb@gftp.org>
masneyb
parents: 504
diff changeset
1930 curfle->size = gftp_get_file_size (transfer->fromreq, curfle->file);
b6ce74de1cd9 2004-7-24 Brian Masney <masneyb@gftp.org>
masneyb
parents: 504
diff changeset
1931 if (curfle->size < 0)
b6ce74de1cd9 2004-7-24 Brian Masney <masneyb@gftp.org>
masneyb
parents: 504
diff changeset
1932 return (curfle->size);
b6ce74de1cd9 2004-7-24 Brian Masney <masneyb@gftp.org>
masneyb
parents: 504
diff changeset
1933 }
381
1c86bcb0b232 2003-2-1 Brian Masney <masneyb@gftp.org>
masneyb
parents: 377
diff changeset
1934
1c86bcb0b232 2003-2-1 Brian Masney <masneyb@gftp.org>
masneyb
parents: 377
diff changeset
1935 if (transfer->toreq && curfle->destfile == NULL)
1c86bcb0b232 2003-2-1 Brian Masney <masneyb@gftp.org>
masneyb
parents: 377
diff changeset
1936 curfle->destfile = gftp_build_path (transfer->toreq->directory,
1c86bcb0b232 2003-2-1 Brian Masney <masneyb@gftp.org>
masneyb
parents: 377
diff changeset
1937 curfle->file, NULL);
1c86bcb0b232 2003-2-1 Brian Masney <masneyb@gftp.org>
masneyb
parents: 377
diff changeset
1938
1c86bcb0b232 2003-2-1 Brian Masney <masneyb@gftp.org>
masneyb
parents: 377
diff changeset
1939 if (transfer->fromreq->directory != NULL &&
509
b6ce74de1cd9 2004-7-24 Brian Masney <masneyb@gftp.org>
masneyb
parents: 504
diff changeset
1940 *transfer->fromreq->directory != '\0' && *curfle->file != '/')
381
1c86bcb0b232 2003-2-1 Brian Masney <masneyb@gftp.org>
masneyb
parents: 377
diff changeset
1941 {
1c86bcb0b232 2003-2-1 Brian Masney <masneyb@gftp.org>
masneyb
parents: 377
diff changeset
1942 newname = gftp_build_path (transfer->fromreq->directory,
1c86bcb0b232 2003-2-1 Brian Masney <masneyb@gftp.org>
masneyb
parents: 377
diff changeset
1943 curfle->file, NULL);
1c86bcb0b232 2003-2-1 Brian Masney <masneyb@gftp.org>
masneyb
parents: 377
diff changeset
1944 g_free (curfle->file);
1c86bcb0b232 2003-2-1 Brian Masney <masneyb@gftp.org>
masneyb
parents: 377
diff changeset
1945 curfle->file = newname;
1c86bcb0b232 2003-2-1 Brian Masney <masneyb@gftp.org>
masneyb
parents: 377
diff changeset
1946 }
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1947
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1948 if (lastlist->next == NULL)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1949 break;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1950 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1951
509
b6ce74de1cd9 2004-7-24 Brian Masney <masneyb@gftp.org>
masneyb
parents: 504
diff changeset
1952 if (dirhash != NULL)
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1953 gftp_destroy_dir_hash (dirhash);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1954
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1955 oldfromdir = oldtodir = NULL;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1956 remotechanged = 0;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1957 forcecd = 0;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1958 for (templist = transfer->files; templist != NULL; templist = templist->next)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1959 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1960 curfle = templist->data;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1961
500
ba50a7085d93 2004-7-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 499
diff changeset
1962 if (S_ISLNK (curfle->st_mode) && !S_ISDIR (curfle->st_mode))
ba50a7085d93 2004-7-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 499
diff changeset
1963 {
520
e67a52327b24 2004-7-27 Brian Masney <masneyb@gftp.org>
masneyb
parents: 518
diff changeset
1964 st_mode = 0;
e67a52327b24 2004-7-27 Brian Masney <masneyb@gftp.org>
masneyb
parents: 518
diff changeset
1965 ret = gftp_stat_filename (transfer->fromreq, curfle->file, &st_mode);
e67a52327b24 2004-7-27 Brian Masney <masneyb@gftp.org>
masneyb
parents: 518
diff changeset
1966 if (ret < 0)
e67a52327b24 2004-7-27 Brian Masney <masneyb@gftp.org>
masneyb
parents: 518
diff changeset
1967 return (ret);
509
b6ce74de1cd9 2004-7-24 Brian Masney <masneyb@gftp.org>
masneyb
parents: 504
diff changeset
1968 else if (S_ISDIR (st_mode))
500
ba50a7085d93 2004-7-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 499
diff changeset
1969 curfle->st_mode = st_mode;
ba50a7085d93 2004-7-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 499
diff changeset
1970 }
ba50a7085d93 2004-7-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 499
diff changeset
1971
ba50a7085d93 2004-7-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 499
diff changeset
1972 if (curfle->st_mode & S_IFDIR)
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1973 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1974 oldfromdir = transfer->fromreq->directory;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1975 transfer->fromreq->directory = curfle->file;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1976
509
b6ce74de1cd9 2004-7-24 Brian Masney <masneyb@gftp.org>
masneyb
parents: 504
diff changeset
1977 if (transfer->toreq != NULL)
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1978 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1979 oldtodir = transfer->toreq->directory;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1980 transfer->toreq->directory = curfle->destfile;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1981 }
509
b6ce74de1cd9 2004-7-24 Brian Masney <masneyb@gftp.org>
masneyb
parents: 504
diff changeset
1982
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1983 forcecd = 1;
509
b6ce74de1cd9 2004-7-24 Brian Masney <masneyb@gftp.org>
masneyb
parents: 504
diff changeset
1984 ret = gftp_set_directory (transfer->fromreq,
b6ce74de1cd9 2004-7-24 Brian Masney <masneyb@gftp.org>
masneyb
parents: 504
diff changeset
1985 transfer->fromreq->directory);
b6ce74de1cd9 2004-7-24 Brian Masney <masneyb@gftp.org>
masneyb
parents: 504
diff changeset
1986 if (ret < 0)
b6ce74de1cd9 2004-7-24 Brian Masney <masneyb@gftp.org>
masneyb
parents: 504
diff changeset
1987 return (ret);
b6ce74de1cd9 2004-7-24 Brian Masney <masneyb@gftp.org>
masneyb
parents: 504
diff changeset
1988
b6ce74de1cd9 2004-7-24 Brian Masney <masneyb@gftp.org>
masneyb
parents: 504
diff changeset
1989 if (curfle->startsize > 0 && transfer->toreq != NULL)
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1990 {
509
b6ce74de1cd9 2004-7-24 Brian Masney <masneyb@gftp.org>
masneyb
parents: 504
diff changeset
1991 remotechanged = 1;
b6ce74de1cd9 2004-7-24 Brian Masney <masneyb@gftp.org>
masneyb
parents: 504
diff changeset
1992 ret = gftp_set_directory (transfer->toreq,
b6ce74de1cd9 2004-7-24 Brian Masney <masneyb@gftp.org>
masneyb
parents: 504
diff changeset
1993 transfer->toreq->directory);
469
2ad1916dc611 2004-5-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 463
diff changeset
1994 if (ret < 0)
509
b6ce74de1cd9 2004-7-24 Brian Masney <masneyb@gftp.org>
masneyb
parents: 504
diff changeset
1995 return (ret);
b6ce74de1cd9 2004-7-24 Brian Masney <masneyb@gftp.org>
masneyb
parents: 504
diff changeset
1996 }
b6ce74de1cd9 2004-7-24 Brian Masney <masneyb@gftp.org>
masneyb
parents: 504
diff changeset
1997
b6ce74de1cd9 2004-7-24 Brian Masney <masneyb@gftp.org>
masneyb
parents: 504
diff changeset
1998 ret = 0;
b6ce74de1cd9 2004-7-24 Brian Masney <masneyb@gftp.org>
masneyb
parents: 504
diff changeset
1999 lastlist->next = gftp_get_dir_listing (transfer,
b6ce74de1cd9 2004-7-24 Brian Masney <masneyb@gftp.org>
masneyb
parents: 504
diff changeset
2000 curfle->startsize > 0,
b6ce74de1cd9 2004-7-24 Brian Masney <masneyb@gftp.org>
masneyb
parents: 504
diff changeset
2001 &ret);
b6ce74de1cd9 2004-7-24 Brian Masney <masneyb@gftp.org>
masneyb
parents: 504
diff changeset
2002 if (ret < 0)
b6ce74de1cd9 2004-7-24 Brian Masney <masneyb@gftp.org>
masneyb
parents: 504
diff changeset
2003 return (ret);
b6ce74de1cd9 2004-7-24 Brian Masney <masneyb@gftp.org>
masneyb
parents: 504
diff changeset
2004
b6ce74de1cd9 2004-7-24 Brian Masney <masneyb@gftp.org>
masneyb
parents: 504
diff changeset
2005 if (lastlist->next != NULL)
b6ce74de1cd9 2004-7-24 Brian Masney <masneyb@gftp.org>
masneyb
parents: 504
diff changeset
2006 {
b6ce74de1cd9 2004-7-24 Brian Masney <masneyb@gftp.org>
masneyb
parents: 504
diff changeset
2007 lastlist->next->prev = lastlist;
b6ce74de1cd9 2004-7-24 Brian Masney <masneyb@gftp.org>
masneyb
parents: 504
diff changeset
2008 for (; lastlist->next != NULL; lastlist = lastlist->next);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
2009 }
509
b6ce74de1cd9 2004-7-24 Brian Masney <masneyb@gftp.org>
masneyb
parents: 504
diff changeset
2010
b6ce74de1cd9 2004-7-24 Brian Masney <masneyb@gftp.org>
masneyb
parents: 504
diff changeset
2011 transfer->numdirs++;
b6ce74de1cd9 2004-7-24 Brian Masney <masneyb@gftp.org>
masneyb
parents: 504
diff changeset
2012 if (update_func != NULL)
b6ce74de1cd9 2004-7-24 Brian Masney <masneyb@gftp.org>
masneyb
parents: 504
diff changeset
2013 update_func (transfer);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
2014
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
2015 transfer->fromreq->directory = oldfromdir;
509
b6ce74de1cd9 2004-7-24 Brian Masney <masneyb@gftp.org>
masneyb
parents: 504
diff changeset
2016 if (transfer->toreq != NULL)
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
2017 transfer->toreq->directory = oldtodir;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
2018 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
2019 else
122
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 107
diff changeset
2020 transfer->numfiles++;
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
2021 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
2022
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
2023 if (forcecd)
509
b6ce74de1cd9 2004-7-24 Brian Masney <masneyb@gftp.org>
masneyb
parents: 504
diff changeset
2024 {
b6ce74de1cd9 2004-7-24 Brian Masney <masneyb@gftp.org>
masneyb
parents: 504
diff changeset
2025 ret = gftp_set_directory (transfer->fromreq,
b6ce74de1cd9 2004-7-24 Brian Masney <masneyb@gftp.org>
masneyb
parents: 504
diff changeset
2026 transfer->fromreq->directory);
b6ce74de1cd9 2004-7-24 Brian Masney <masneyb@gftp.org>
masneyb
parents: 504
diff changeset
2027 if (ret < 0)
b6ce74de1cd9 2004-7-24 Brian Masney <masneyb@gftp.org>
masneyb
parents: 504
diff changeset
2028 return (ret);
b6ce74de1cd9 2004-7-24 Brian Masney <masneyb@gftp.org>
masneyb
parents: 504
diff changeset
2029 }
b6ce74de1cd9 2004-7-24 Brian Masney <masneyb@gftp.org>
masneyb
parents: 504
diff changeset
2030
b6ce74de1cd9 2004-7-24 Brian Masney <masneyb@gftp.org>
masneyb
parents: 504
diff changeset
2031 if (remotechanged && transfer->toreq != NULL)
b6ce74de1cd9 2004-7-24 Brian Masney <masneyb@gftp.org>
masneyb
parents: 504
diff changeset
2032 {
b6ce74de1cd9 2004-7-24 Brian Masney <masneyb@gftp.org>
masneyb
parents: 504
diff changeset
2033 ret = gftp_set_directory (transfer->toreq, transfer->toreq->directory);
b6ce74de1cd9 2004-7-24 Brian Masney <masneyb@gftp.org>
masneyb
parents: 504
diff changeset
2034 if (ret < 0)
b6ce74de1cd9 2004-7-24 Brian Masney <masneyb@gftp.org>
masneyb
parents: 504
diff changeset
2035 return (ret);
b6ce74de1cd9 2004-7-24 Brian Masney <masneyb@gftp.org>
masneyb
parents: 504
diff changeset
2036 }
b6ce74de1cd9 2004-7-24 Brian Masney <masneyb@gftp.org>
masneyb
parents: 504
diff changeset
2037
b6ce74de1cd9 2004-7-24 Brian Masney <masneyb@gftp.org>
masneyb
parents: 504
diff changeset
2038 if (update_func != NULL)
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
2039 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
2040 transfer->numfiles = transfer->numdirs = -1;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
2041 update_func (transfer);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
2042 }
509
b6ce74de1cd9 2004-7-24 Brian Masney <masneyb@gftp.org>
masneyb
parents: 504
diff changeset
2043
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
2044 return (0);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
2045 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
2046
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
2047
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
2048 #if defined (HAVE_GETADDRINFO) && defined (HAVE_GAI_STRERROR)
122
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 107
diff changeset
2049 static int
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
2050 get_port (struct addrinfo *addr)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
2051 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
2052 struct sockaddr_in * saddr;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
2053 int port;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
2054
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
2055 if (addr->ai_family == AF_INET)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
2056 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
2057 saddr = (struct sockaddr_in *) addr->ai_addr;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
2058 port = ntohs (saddr->sin_port);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
2059 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
2060 else
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
2061 port = 0;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
2062
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
2063 return (port);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
2064 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
2065 #endif
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
2066
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
2067
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
2068 int
122
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 107
diff changeset
2069 gftp_connect_server (gftp_request * request, char *service,
516
fbb5a02beddb 2004-7-26 Brian Masney <masneyb@gftp.org>
masneyb
parents: 512
diff changeset
2070 char *proxy_hostname, unsigned int proxy_port)
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
2071 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
2072 char *connect_host, *disphost;
516
fbb5a02beddb 2004-7-26 Brian Masney <masneyb@gftp.org>
masneyb
parents: 512
diff changeset
2073 unsigned int port;
fbb5a02beddb 2004-7-26 Brian Masney <masneyb@gftp.org>
masneyb
parents: 512
diff changeset
2074 int sock = -1;
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
2075 #if defined (HAVE_GETADDRINFO) && defined (HAVE_GAI_STRERROR)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
2076 struct addrinfo hints, *res;
463
39d9cf1bf0df 2004-4-14 Brian Masney <masneyb@gftp.org>
masneyb
parents: 460
diff changeset
2077 intptr_t enable_ipv6;
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
2078 char serv[8];
463
39d9cf1bf0df 2004-4-14 Brian Masney <masneyb@gftp.org>
masneyb
parents: 460
diff changeset
2079 int errnum;
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
2080
516
fbb5a02beddb 2004-7-26 Brian Masney <masneyb@gftp.org>
masneyb
parents: 512
diff changeset
2081 if ((errnum = gftp_need_proxy (request, service, proxy_hostname,
fbb5a02beddb 2004-7-26 Brian Masney <masneyb@gftp.org>
masneyb
parents: 512
diff changeset
2082 proxy_port)) < 0)
fbb5a02beddb 2004-7-26 Brian Masney <masneyb@gftp.org>
masneyb
parents: 512
diff changeset
2083 return (errnum);
fbb5a02beddb 2004-7-26 Brian Masney <masneyb@gftp.org>
masneyb
parents: 512
diff changeset
2084 else
fbb5a02beddb 2004-7-26 Brian Masney <masneyb@gftp.org>
masneyb
parents: 512
diff changeset
2085 {
fbb5a02beddb 2004-7-26 Brian Masney <masneyb@gftp.org>
masneyb
parents: 512
diff changeset
2086 request->use_proxy = errnum;
fbb5a02beddb 2004-7-26 Brian Masney <masneyb@gftp.org>
masneyb
parents: 512
diff changeset
2087 if (request->use_proxy)
fbb5a02beddb 2004-7-26 Brian Masney <masneyb@gftp.org>
masneyb
parents: 512
diff changeset
2088 request->hostp = NULL;
fbb5a02beddb 2004-7-26 Brian Masney <masneyb@gftp.org>
masneyb
parents: 512
diff changeset
2089 }
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
2090
313
32a6b26b7026 2003-11-9 Brian Masney <masneyb@gftp.org>
masneyb
parents: 309
diff changeset
2091 gftp_lookup_request_option (request, "enable_ipv6", &enable_ipv6);
32a6b26b7026 2003-11-9 Brian Masney <masneyb@gftp.org>
masneyb
parents: 309
diff changeset
2092
151
2f15b3000dbc 2003-4-27 Brian Masney <masneyb@gftp.org>
masneyb
parents: 146
diff changeset
2093 request->free_hostp = 1;
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
2094 memset (&hints, 0, sizeof (hints));
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
2095 hints.ai_flags = AI_CANONNAME;
313
32a6b26b7026 2003-11-9 Brian Masney <masneyb@gftp.org>
masneyb
parents: 309
diff changeset
2096
32a6b26b7026 2003-11-9 Brian Masney <masneyb@gftp.org>
masneyb
parents: 309
diff changeset
2097 if (enable_ipv6)
32a6b26b7026 2003-11-9 Brian Masney <masneyb@gftp.org>
masneyb
parents: 309
diff changeset
2098 hints.ai_family = PF_UNSPEC;
32a6b26b7026 2003-11-9 Brian Masney <masneyb@gftp.org>
masneyb
parents: 309
diff changeset
2099 else
32a6b26b7026 2003-11-9 Brian Masney <masneyb@gftp.org>
masneyb
parents: 309
diff changeset
2100 hints.ai_family = AF_INET;
32a6b26b7026 2003-11-9 Brian Masney <masneyb@gftp.org>
masneyb
parents: 309
diff changeset
2101
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
2102 hints.ai_socktype = SOCK_STREAM;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
2103
122
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 107
diff changeset
2104 if (request->use_proxy)
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 107
diff changeset
2105 {
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 107
diff changeset
2106 connect_host = proxy_hostname;
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 107
diff changeset
2107 port = proxy_port;
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 107
diff changeset
2108 }
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 107
diff changeset
2109 else
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 107
diff changeset
2110 {
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 107
diff changeset
2111 connect_host = request->hostname;
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 107
diff changeset
2112 port = request->port;
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 107
diff changeset
2113 }
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
2114
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
2115 if (request->hostp == NULL)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
2116 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
2117 if (port == 0)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
2118 strcpy (serv, service);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
2119 else
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
2120 snprintf (serv, sizeof (serv), "%d", port);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
2121
186
13ca1defdc75 2003-6-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 185
diff changeset
2122 request->logging_function (gftp_logging_misc, request,
168
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 151
diff changeset
2123 _("Looking up %s\n"), connect_host);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
2124 if ((errnum = getaddrinfo (connect_host, serv, &hints,
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
2125 &request->hostp)) != 0)
168
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 151
diff changeset
2126 {
186
13ca1defdc75 2003-6-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 185
diff changeset
2127 request->logging_function (gftp_logging_error, request,
168
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 151
diff changeset
2128 _("Cannot look up hostname %s: %s\n"),
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 151
diff changeset
2129 connect_host, gai_strerror (errnum));
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 151
diff changeset
2130 return (GFTP_ERETRYABLE);
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 151
diff changeset
2131 }
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
2132 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
2133
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
2134 disphost = connect_host;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
2135 for (res = request->hostp; res != NULL; res = res->ai_next)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
2136 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
2137 disphost = res->ai_canonname ? res->ai_canonname : connect_host;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
2138 port = get_port (res);
56
a12bcbc2fce4 2002-11-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 48
diff changeset
2139 if (!request->use_proxy)
a12bcbc2fce4 2002-11-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 48
diff changeset
2140 request->port = port;
a12bcbc2fce4 2002-11-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 48
diff changeset
2141
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
2142 if ((sock = socket (res->ai_family, res->ai_socktype,
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
2143 res->ai_protocol)) < 0)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
2144 {
186
13ca1defdc75 2003-6-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 185
diff changeset
2145 request->logging_function (gftp_logging_error, request,
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
2146 _("Failed to create a socket: %s\n"),
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
2147 g_strerror (errno));
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
2148 continue;
66
cd3e457cbc85 2002-11-26 Brian Masney <masneyb@gftp.org>
masneyb
parents: 65
diff changeset
2149 }
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
2150
186
13ca1defdc75 2003-6-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 185
diff changeset
2151 request->logging_function (gftp_logging_misc, request,
168
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 151
diff changeset
2152 _("Trying %s:%d\n"), disphost, port);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
2153
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
2154 if (connect (sock, res->ai_addr, res->ai_addrlen) == -1)
168
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 151
diff changeset
2155 {
186
13ca1defdc75 2003-6-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 185
diff changeset
2156 request->logging_function (gftp_logging_error, request,
168
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 151
diff changeset
2157 _("Cannot connect to %s: %s\n"),
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 151
diff changeset
2158 disphost, g_strerror (errno));
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
2159 close (sock);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
2160 continue;
168
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 151
diff changeset
2161 }
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
2162 break;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
2163 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
2164
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
2165 if (res == NULL)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
2166 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
2167 if (request->hostp != NULL)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
2168 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
2169 freeaddrinfo (request->hostp);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
2170 request->hostp = NULL;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
2171 }
84
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 76
diff changeset
2172 return (GFTP_ERETRYABLE);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
2173 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
2174
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
2175 #else /* !HAVE_GETADDRINFO */
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
2176 struct sockaddr_in remote_address;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
2177 struct servent serv_struct;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
2178 int curhost;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
2179
122
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 107
diff changeset
2180 if ((request->use_proxy = gftp_need_proxy (request, service,
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 107
diff changeset
2181 proxy_hostname, proxy_port)) < 0)
84
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 76
diff changeset
2182 return (request->use_proxy);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
2183 else if (request->use_proxy == 1)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
2184 request->hostp = NULL;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
2185
516
fbb5a02beddb 2004-7-26 Brian Masney <masneyb@gftp.org>
masneyb
parents: 512
diff changeset
2186 g_return_val_if_fail (sock != -1, GFTP_EFATAL);
fbb5a02beddb 2004-7-26 Brian Masney <masneyb@gftp.org>
masneyb
parents: 512
diff changeset
2187
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
2188 if ((sock = socket (AF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
2189 {
186
13ca1defdc75 2003-6-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 185
diff changeset
2190 request->logging_function (gftp_logging_error, request,
313
32a6b26b7026 2003-11-9 Brian Masney <masneyb@gftp.org>
masneyb
parents: 309
diff changeset
2191 _("Failed to create a IPv4 socket: %s\n"),
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
2192 g_strerror (errno));
84
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 76
diff changeset
2193 return (GFTP_ERETRYABLE);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
2194 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
2195
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
2196 memset (&remote_address, 0, sizeof (remote_address));
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
2197 remote_address.sin_family = AF_INET;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
2198
122
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 107
diff changeset
2199 if (request->use_proxy)
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 107
diff changeset
2200 {
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 107
diff changeset
2201 connect_host = proxy_hostname;
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 107
diff changeset
2202 port = proxy_port;
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 107
diff changeset
2203 }
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 107
diff changeset
2204 else
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 107
diff changeset
2205 {
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 107
diff changeset
2206 connect_host = request->hostname;
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 107
diff changeset
2207 port = request->port;
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 107
diff changeset
2208 }
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
2209
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
2210 if (port == 0)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
2211 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
2212 if (!r_getservbyname (service, "tcp", &serv_struct, NULL))
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
2213 {
186
13ca1defdc75 2003-6-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 185
diff changeset
2214 request->logging_function (gftp_logging_error, request,
122
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 107
diff changeset
2215 _("Cannot look up service name %s/tcp. Please check your services file\n"),
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 107
diff changeset
2216 service);
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 107
diff changeset
2217 close (sock);
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 107
diff changeset
2218 return (GFTP_EFATAL);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
2219 }
451
83cfffb2878a 2004-3-26 Brian Masney <masneyb@gftp.org>
masneyb
parents: 443
diff changeset
2220
83cfffb2878a 2004-3-26 Brian Masney <masneyb@gftp.org>
masneyb
parents: 443
diff changeset
2221 port = ntohs (serv_struct.s_port);
56
a12bcbc2fce4 2002-11-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 48
diff changeset
2222
a12bcbc2fce4 2002-11-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 48
diff changeset
2223 if (!request->use_proxy)
451
83cfffb2878a 2004-3-26 Brian Masney <masneyb@gftp.org>
masneyb
parents: 443
diff changeset
2224 request->port = port;
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
2225 }
451
83cfffb2878a 2004-3-26 Brian Masney <masneyb@gftp.org>
masneyb
parents: 443
diff changeset
2226
83cfffb2878a 2004-3-26 Brian Masney <masneyb@gftp.org>
masneyb
parents: 443
diff changeset
2227 remote_address.sin_port = htons (port);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
2228
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
2229 if (request->hostp == NULL)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
2230 {
186
13ca1defdc75 2003-6-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 185
diff changeset
2231 request->logging_function (gftp_logging_misc, request,
168
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 151
diff changeset
2232 _("Looking up %s\n"), connect_host);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
2233 if (!(request->hostp = r_gethostbyname (connect_host, &request->host,
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
2234 NULL)))
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
2235 {
186
13ca1defdc75 2003-6-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 185
diff changeset
2236 request->logging_function (gftp_logging_error, request,
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
2237 _("Cannot look up hostname %s: %s\n"),
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
2238 connect_host, g_strerror (errno));
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
2239 close (sock);
84
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 76
diff changeset
2240 return (GFTP_ERETRYABLE);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
2241 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
2242 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
2243
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
2244 disphost = NULL;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
2245 for (curhost = 0; request->host.h_addr_list[curhost] != NULL; curhost++)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
2246 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
2247 disphost = request->host.h_name;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
2248 memcpy (&remote_address.sin_addr, request->host.h_addr_list[curhost],
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
2249 request->host.h_length);
186
13ca1defdc75 2003-6-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 185
diff changeset
2250 request->logging_function (gftp_logging_misc, request,
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
2251 _("Trying %s:%d\n"),
451
83cfffb2878a 2004-3-26 Brian Masney <masneyb@gftp.org>
masneyb
parents: 443
diff changeset
2252 request->host.h_name, port);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
2253
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
2254 if (connect (sock, (struct sockaddr *) &remote_address,
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
2255 sizeof (remote_address)) == -1)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
2256 {
186
13ca1defdc75 2003-6-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 185
diff changeset
2257 request->logging_function (gftp_logging_error, request,
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
2258 _("Cannot connect to %s: %s\n"),
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
2259 connect_host, g_strerror (errno));
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
2260 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
2261 break;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
2262 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
2263
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
2264 if (request->host.h_addr_list[curhost] == NULL)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
2265 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
2266 close (sock);
84
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 76
diff changeset
2267 return (GFTP_ERETRYABLE);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
2268 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
2269 #endif /* HAVE_GETADDRINFO */
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
2270
182
33b394ebba68 2003-6-15 Brian Masney <masneyb@gftp.org>
masneyb
parents: 179
diff changeset
2271 if (fcntl (sock, F_SETFD, 1) == -1)
33b394ebba68 2003-6-15 Brian Masney <masneyb@gftp.org>
masneyb
parents: 179
diff changeset
2272 {
186
13ca1defdc75 2003-6-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 185
diff changeset
2273 request->logging_function (gftp_logging_error, request,
182
33b394ebba68 2003-6-15 Brian Masney <masneyb@gftp.org>
masneyb
parents: 179
diff changeset
2274 _("Error: Cannot set close on exec flag: %s\n"),
33b394ebba68 2003-6-15 Brian Masney <masneyb@gftp.org>
masneyb
parents: 179
diff changeset
2275 g_strerror (errno));
33b394ebba68 2003-6-15 Brian Masney <masneyb@gftp.org>
masneyb
parents: 179
diff changeset
2276
33b394ebba68 2003-6-15 Brian Masney <masneyb@gftp.org>
masneyb
parents: 179
diff changeset
2277 return (GFTP_ERETRYABLE);
33b394ebba68 2003-6-15 Brian Masney <masneyb@gftp.org>
masneyb
parents: 179
diff changeset
2278 }
33b394ebba68 2003-6-15 Brian Masney <masneyb@gftp.org>
masneyb
parents: 179
diff changeset
2279
186
13ca1defdc75 2003-6-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 185
diff changeset
2280 request->logging_function (gftp_logging_misc, request,
168
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 151
diff changeset
2281 _("Connected to %s:%d\n"), connect_host, port);
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
2282
168
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 151
diff changeset
2283 if (gftp_fd_set_sockblocking (request, sock, 1) < 0)
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
2284 {
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
2285 close (sock);
84
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 76
diff changeset
2286 return (GFTP_ERETRYABLE);
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
2287 }
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
2288
169
d40f9db52cdf 2003-6-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 168
diff changeset
2289 request->datafd = sock;
168
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 151
diff changeset
2290
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 151
diff changeset
2291 if (request->post_connect != NULL)
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 151
diff changeset
2292 return (request->post_connect (request));
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 151
diff changeset
2293
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 151
diff changeset
2294 return (0);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
2295 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
2296
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
2297
177
aec4b4541d3a 2003-6-9 Brian Masney <masneyb@gftp.org>
masneyb
parents: 173
diff changeset
2298 int
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
2299 gftp_set_config_options (gftp_request * request)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
2300 {
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
2301 if (request->set_config_options != NULL)
177
aec4b4541d3a 2003-6-9 Brian Masney <masneyb@gftp.org>
masneyb
parents: 173
diff changeset
2302 return (request->set_config_options (request));
aec4b4541d3a 2003-6-9 Brian Masney <masneyb@gftp.org>
masneyb
parents: 173
diff changeset
2303 else
aec4b4541d3a 2003-6-9 Brian Masney <masneyb@gftp.org>
masneyb
parents: 173
diff changeset
2304 return (0);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
2305 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
2306
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
2307
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
2308 void
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
2309 print_file_list (GList * list)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
2310 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
2311 gftp_file * tempfle;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
2312 GList * templist;
499
39e9945288ea 2004-7-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 498
diff changeset
2313 char *attribs;
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
2314
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
2315 printf ("--START OF FILE LISTING - TOP TO BOTTOM--\n");
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
2316 for (templist = list; ; templist = templist->next)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
2317 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
2318 tempfle = templist->data;
499
39e9945288ea 2004-7-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 498
diff changeset
2319 attribs = gftp_convert_attributes_from_mode_t (tempfle->st_mode);
39e9945288ea 2004-7-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 498
diff changeset
2320
14
83090328581e * More largefile support. Hopefully all that is left is the configure stuff
masneyb
parents: 7
diff changeset
2321 #if defined (_LARGEFILE_SOURCE)
83090328581e * More largefile support. Hopefully all that is left is the configure stuff
masneyb
parents: 7
diff changeset
2322 printf ("%s:%s:%lld:%lld:%s:%s:%s\n",
372
44b792841e3f 2003-1-18 Brian Masney <masneyb@gftp.org>
masneyb
parents: 367
diff changeset
2323 tempfle->file, tempfle->destfile,
516
fbb5a02beddb 2004-7-26 Brian Masney <masneyb@gftp.org>
masneyb
parents: 512
diff changeset
2324 tempfle->size, tempfle->startsize,
499
39e9945288ea 2004-7-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 498
diff changeset
2325 tempfle->user, tempfle->group, attribs);
14
83090328581e * More largefile support. Hopefully all that is left is the configure stuff
masneyb
parents: 7
diff changeset
2326 #else
83090328581e * More largefile support. Hopefully all that is left is the configure stuff
masneyb
parents: 7
diff changeset
2327 printf ("%s:%s:%ld:%ld:%s:%s:%s\n",
16
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
2328 tempfle->file, tempfle->destfile,
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
2329 tempfle->size, tempfle->startsize,
499
39e9945288ea 2004-7-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 498
diff changeset
2330 tempfle->user, tempfle->group, attribs);
372
44b792841e3f 2003-1-18 Brian Masney <masneyb@gftp.org>
masneyb
parents: 367
diff changeset
2331 #endif
499
39e9945288ea 2004-7-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 498
diff changeset
2332
39e9945288ea 2004-7-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 498
diff changeset
2333 g_free (attribs);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
2334 if (templist->next == NULL)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
2335 break;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
2336 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
2337
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
2338 printf ("--START OF FILE LISTING - BOTTOM TO TOP--\n");
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
2339 for (; ; templist = templist->prev)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
2340 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
2341 tempfle = templist->data;
499
39e9945288ea 2004-7-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 498
diff changeset
2342 attribs = gftp_convert_attributes_from_mode_t (tempfle->st_mode);
39e9945288ea 2004-7-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 498
diff changeset
2343
14
83090328581e * More largefile support. Hopefully all that is left is the configure stuff
masneyb
parents: 7
diff changeset
2344 #if defined (_LARGEFILE_SOURCE)
83090328581e * More largefile support. Hopefully all that is left is the configure stuff
masneyb
parents: 7
diff changeset
2345 printf ("%s:%s:%lld:%lld:%s:%s:%s\n",
372
44b792841e3f 2003-1-18 Brian Masney <masneyb@gftp.org>
masneyb
parents: 367
diff changeset
2346 tempfle->file, tempfle->destfile,
516
fbb5a02beddb 2004-7-26 Brian Masney <masneyb@gftp.org>
masneyb
parents: 512
diff changeset
2347 tempfle->size, tempfle->startsize,
499
39e9945288ea 2004-7-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 498
diff changeset
2348 tempfle->user, tempfle->group, attribs);
14
83090328581e * More largefile support. Hopefully all that is left is the configure stuff
masneyb
parents: 7
diff changeset
2349 #else
83090328581e * More largefile support. Hopefully all that is left is the configure stuff
masneyb
parents: 7
diff changeset
2350 printf ("%s:%s:%ld:%ld:%s:%s:%s\n",
16
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
2351 tempfle->file, tempfle->destfile,
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
2352 tempfle->size, tempfle->startsize,
499
39e9945288ea 2004-7-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 498
diff changeset
2353 tempfle->user, tempfle->group, attribs);
372
44b792841e3f 2003-1-18 Brian Masney <masneyb@gftp.org>
masneyb
parents: 367
diff changeset
2354 #endif
499
39e9945288ea 2004-7-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 498
diff changeset
2355
39e9945288ea 2004-7-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 498
diff changeset
2356 g_free (attribs);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
2357 if (templist == list)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
2358 break;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
2359 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
2360 printf ("--END OF FILE LISTING--\n");
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
2361 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
2362
41
4bcfaf6307b5 2002-10-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
2363
201
0098dae654a5 2003-6-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 199
diff changeset
2364 void
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
2365 gftp_free_getline_buffer (gftp_getline_buffer ** rbuf)
41
4bcfaf6307b5 2002-10-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
2366 {
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
2367 g_free ((*rbuf)->buffer);
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
2368 g_free (*rbuf);
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
2369 *rbuf = NULL;
41
4bcfaf6307b5 2002-10-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
2370 }
4bcfaf6307b5 2002-10-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
2371
4bcfaf6307b5 2002-10-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
2372
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
2373 ssize_t
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
2374 gftp_get_line (gftp_request * request, gftp_getline_buffer ** rbuf,
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
2375 char * str, size_t len, int fd)
41
4bcfaf6307b5 2002-10-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
2376 {
168
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 151
diff changeset
2377 ssize_t (*read_function) (gftp_request * request, void *ptr, size_t size,
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 151
diff changeset
2378 int fd);
516
fbb5a02beddb 2004-7-26 Brian Masney <masneyb@gftp.org>
masneyb
parents: 512
diff changeset
2379 char *pos, *nextpos;
fbb5a02beddb 2004-7-26 Brian Masney <masneyb@gftp.org>
masneyb
parents: 512
diff changeset
2380 size_t rlen, nslen;
179
8d933999bba6 2003-6-14 Brian Masney <masneyb@gftp.org>
masneyb
parents: 177
diff changeset
2381 int end_of_buffer;
516
fbb5a02beddb 2004-7-26 Brian Masney <masneyb@gftp.org>
masneyb
parents: 512
diff changeset
2382 ssize_t ret;
168
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 151
diff changeset
2383
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 151
diff changeset
2384 if (request == NULL || request->read_function == NULL)
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 151
diff changeset
2385 read_function = gftp_fd_read;
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 151
diff changeset
2386 else
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 151
diff changeset
2387 read_function = request->read_function;
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
2388
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
2389 if (*rbuf == NULL)
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
2390 {
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
2391 *rbuf = g_malloc0 (sizeof (**rbuf));
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
2392 (*rbuf)->max_bufsize = len;
249
094e83b55cb1 2003-8-7 Brian Masney <masneyb@gftp.org>
masneyb
parents: 248
diff changeset
2393 (*rbuf)->buffer = g_malloc0 ((*rbuf)->max_bufsize + 1);
168
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 151
diff changeset
2394
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 151
diff changeset
2395 if ((ret = read_function (request, (*rbuf)->buffer,
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 151
diff changeset
2396 (*rbuf)->max_bufsize, fd)) <= 0)
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
2397 {
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
2398 gftp_free_getline_buffer (rbuf);
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
2399 return (ret);
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
2400 }
60
8a9324fb63a4 2002-11-21 Brian Masney <masneyb@gftp.org>
masneyb
parents: 58
diff changeset
2401 (*rbuf)->buffer[ret] = '\0';
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
2402 (*rbuf)->cur_bufsize = ret;
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
2403 (*rbuf)->curpos = (*rbuf)->buffer;
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
2404 }
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
2405
516
fbb5a02beddb 2004-7-26 Brian Masney <masneyb@gftp.org>
masneyb
parents: 512
diff changeset
2406 ret = 0;
fbb5a02beddb 2004-7-26 Brian Masney <masneyb@gftp.org>
masneyb
parents: 512
diff changeset
2407 while (1)
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
2408 {
179
8d933999bba6 2003-6-14 Brian Masney <masneyb@gftp.org>
masneyb
parents: 177
diff changeset
2409 pos = strchr ((*rbuf)->curpos, '\n');
8d933999bba6 2003-6-14 Brian Masney <masneyb@gftp.org>
masneyb
parents: 177
diff changeset
2410 end_of_buffer = (*rbuf)->curpos == (*rbuf)->buffer &&
8d933999bba6 2003-6-14 Brian Masney <masneyb@gftp.org>
masneyb
parents: 177
diff changeset
2411 ((*rbuf)->max_bufsize == (*rbuf)->cur_bufsize || (*rbuf)->eof);
8d933999bba6 2003-6-14 Brian Masney <masneyb@gftp.org>
masneyb
parents: 177
diff changeset
2412
8d933999bba6 2003-6-14 Brian Masney <masneyb@gftp.org>
masneyb
parents: 177
diff changeset
2413 if ((*rbuf)->cur_bufsize > 0 && (pos != NULL || end_of_buffer))
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
2414 {
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
2415 if (pos != NULL)
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
2416 {
516
fbb5a02beddb 2004-7-26 Brian Masney <masneyb@gftp.org>
masneyb
parents: 512
diff changeset
2417 nslen = pos - (*rbuf)->curpos + 1;
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
2418 nextpos = pos + 1;
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
2419 if (pos > (*rbuf)->curpos && *(pos - 1) == '\r')
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
2420 pos--;
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
2421 *pos = '\0';
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
2422 }
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
2423 else
249
094e83b55cb1 2003-8-7 Brian Masney <masneyb@gftp.org>
masneyb
parents: 248
diff changeset
2424 {
516
fbb5a02beddb 2004-7-26 Brian Masney <masneyb@gftp.org>
masneyb
parents: 512
diff changeset
2425 nslen = (*rbuf)->cur_bufsize;
249
094e83b55cb1 2003-8-7 Brian Masney <masneyb@gftp.org>
masneyb
parents: 248
diff changeset
2426 nextpos = NULL;
094e83b55cb1 2003-8-7 Brian Masney <masneyb@gftp.org>
masneyb
parents: 248
diff changeset
2427
094e83b55cb1 2003-8-7 Brian Masney <masneyb@gftp.org>
masneyb
parents: 248
diff changeset
2428 /* This is not an overflow since we allocated one extra byte to
094e83b55cb1 2003-8-7 Brian Masney <masneyb@gftp.org>
masneyb
parents: 248
diff changeset
2429 buffer above */
516
fbb5a02beddb 2004-7-26 Brian Masney <masneyb@gftp.org>
masneyb
parents: 512
diff changeset
2430 ((*rbuf)->curpos)[nslen] = '\0';
249
094e83b55cb1 2003-8-7 Brian Masney <masneyb@gftp.org>
masneyb
parents: 248
diff changeset
2431 }
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
2432
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
2433 strncpy (str, (*rbuf)->curpos, len);
249
094e83b55cb1 2003-8-7 Brian Masney <masneyb@gftp.org>
masneyb
parents: 248
diff changeset
2434 str[len - 1] = '\0';
516
fbb5a02beddb 2004-7-26 Brian Masney <masneyb@gftp.org>
masneyb
parents: 512
diff changeset
2435 (*rbuf)->cur_bufsize -= nslen;
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
2436
168
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 151
diff changeset
2437 if (nextpos != NULL)
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 151
diff changeset
2438 (*rbuf)->curpos = nextpos;
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 151
diff changeset
2439 else
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 151
diff changeset
2440 (*rbuf)->cur_bufsize = 0;
516
fbb5a02beddb 2004-7-26 Brian Masney <masneyb@gftp.org>
masneyb
parents: 512
diff changeset
2441
fbb5a02beddb 2004-7-26 Brian Masney <masneyb@gftp.org>
masneyb
parents: 512
diff changeset
2442 ret = nslen;
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
2443 break;
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
2444 }
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
2445 else
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
2446 {
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
2447 if ((*rbuf)->cur_bufsize == 0 || *(*rbuf)->curpos == '\0')
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
2448 {
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
2449 rlen = (*rbuf)->max_bufsize;
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
2450 pos = (*rbuf)->buffer;
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
2451 }
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
2452 else
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
2453 {
168
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 151
diff changeset
2454 memmove ((*rbuf)->buffer, (*rbuf)->curpos, (*rbuf)->cur_bufsize);
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 151
diff changeset
2455 pos = (*rbuf)->buffer + (*rbuf)->cur_bufsize;
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 151
diff changeset
2456 rlen = (*rbuf)->max_bufsize - (*rbuf)->cur_bufsize;
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
2457 }
168
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 151
diff changeset
2458
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
2459 (*rbuf)->curpos = (*rbuf)->buffer;
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
2460
209
d79e2782eb1b 2003-7-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 207
diff changeset
2461 if ((*rbuf)->eof)
d79e2782eb1b 2003-7-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 207
diff changeset
2462 ret = 0;
d79e2782eb1b 2003-7-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 207
diff changeset
2463 else
d79e2782eb1b 2003-7-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 207
diff changeset
2464 ret = read_function (request, pos, rlen, fd);
d79e2782eb1b 2003-7-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 207
diff changeset
2465
d79e2782eb1b 2003-7-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 207
diff changeset
2466 if (ret < 0)
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
2467 {
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
2468 gftp_free_getline_buffer (rbuf);
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
2469 return (ret);
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
2470 }
179
8d933999bba6 2003-6-14 Brian Masney <masneyb@gftp.org>
masneyb
parents: 177
diff changeset
2471 else if (ret == 0)
168
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 151
diff changeset
2472 {
179
8d933999bba6 2003-6-14 Brian Masney <masneyb@gftp.org>
masneyb
parents: 177
diff changeset
2473 if ((*rbuf)->cur_bufsize == 0)
8d933999bba6 2003-6-14 Brian Masney <masneyb@gftp.org>
masneyb
parents: 177
diff changeset
2474 {
8d933999bba6 2003-6-14 Brian Masney <masneyb@gftp.org>
masneyb
parents: 177
diff changeset
2475 gftp_free_getline_buffer (rbuf);
8d933999bba6 2003-6-14 Brian Masney <masneyb@gftp.org>
masneyb
parents: 177
diff changeset
2476 return (ret);
8d933999bba6 2003-6-14 Brian Masney <masneyb@gftp.org>
masneyb
parents: 177
diff changeset
2477 }
8d933999bba6 2003-6-14 Brian Masney <masneyb@gftp.org>
masneyb
parents: 177
diff changeset
2478
8d933999bba6 2003-6-14 Brian Masney <masneyb@gftp.org>
masneyb
parents: 177
diff changeset
2479 (*rbuf)->eof = 1;
168
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 151
diff changeset
2480 }
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 151
diff changeset
2481
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 151
diff changeset
2482 (*rbuf)->cur_bufsize += ret;
215
3d6e024dbf31 2003-7-7 Brian Masney <masneyb@gftp.org>
masneyb
parents: 211
diff changeset
2483 (*rbuf)->curpos[(*rbuf)->cur_bufsize] = '\0';
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
2484 }
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
2485 }
516
fbb5a02beddb 2004-7-26 Brian Masney <masneyb@gftp.org>
masneyb
parents: 512
diff changeset
2486
fbb5a02beddb 2004-7-26 Brian Masney <masneyb@gftp.org>
masneyb
parents: 512
diff changeset
2487 return (ret);
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
2488 }
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
2489
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
2490
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
2491 ssize_t
168
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 151
diff changeset
2492 gftp_fd_read (gftp_request * request, void *ptr, size_t size, int fd)
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
2493 {
325
0fcc6468a0af 2003-12-4 Brian Masney <masneyb@gftp.org>
masneyb
parents: 313
diff changeset
2494 intptr_t network_timeout;
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
2495 struct timeval tv;
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
2496 fd_set fset;
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
2497 ssize_t ret;
41
4bcfaf6307b5 2002-10-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
2498
122
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 107
diff changeset
2499 gftp_lookup_request_option (request, "network_timeout", &network_timeout);
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 107
diff changeset
2500
41
4bcfaf6307b5 2002-10-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
2501 errno = 0;
4bcfaf6307b5 2002-10-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
2502 ret = 0;
518
c6a6e908dbaf 2004-7-27 Brian Masney <masneyb@gftp.org>
masneyb
parents: 516
diff changeset
2503
c6a6e908dbaf 2004-7-27 Brian Masney <masneyb@gftp.org>
masneyb
parents: 516
diff changeset
2504 while (1)
41
4bcfaf6307b5 2002-10-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
2505 {
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
2506 FD_ZERO (&fset);
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
2507 FD_SET (fd, &fset);
122
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 107
diff changeset
2508 tv.tv_sec = network_timeout;
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
2509 tv.tv_usec = 0;
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
2510 ret = select (fd + 1, &fset, NULL, NULL, &tv);
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
2511 if (ret == -1 && errno == EINTR)
41
4bcfaf6307b5 2002-10-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
2512 {
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
2513 if (request && request->cancel)
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
2514 break;
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
2515 else
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
2516 continue;
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
2517 }
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
2518 else if (ret <= 0)
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
2519 {
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
2520 if (request != NULL)
41
4bcfaf6307b5 2002-10-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
2521 {
186
13ca1defdc75 2003-6-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 185
diff changeset
2522 request->logging_function (gftp_logging_error, request,
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
2523 _("Connection to %s timed out\n"),
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
2524 request->hostname);
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
2525 gftp_disconnect (request);
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
2526 }
84
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 76
diff changeset
2527 return (GFTP_ERETRYABLE);
41
4bcfaf6307b5 2002-10-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
2528 }
4bcfaf6307b5 2002-10-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
2529
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
2530 if ((ret = read (fd, ptr, size)) < 0)
41
4bcfaf6307b5 2002-10-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
2531 {
4bcfaf6307b5 2002-10-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
2532 if (errno == EINTR)
4bcfaf6307b5 2002-10-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
2533 {
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
2534 if (request != NULL && request->cancel)
41
4bcfaf6307b5 2002-10-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
2535 break;
4bcfaf6307b5 2002-10-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
2536 else
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
2537 continue;
518
c6a6e908dbaf 2004-7-27 Brian Masney <masneyb@gftp.org>
masneyb
parents: 516
diff changeset
2538 }
41
4bcfaf6307b5 2002-10-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
2539
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
2540 if (request != NULL)
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
2541 {
186
13ca1defdc75 2003-6-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 185
diff changeset
2542 request->logging_function (gftp_logging_error, request,
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
2543 _("Error: Could not read from socket: %s\n"),
41
4bcfaf6307b5 2002-10-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
2544 g_strerror (errno));
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
2545 gftp_disconnect (request);
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
2546 }
84
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 76
diff changeset
2547 return (GFTP_ERETRYABLE);
41
4bcfaf6307b5 2002-10-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
2548 }
518
c6a6e908dbaf 2004-7-27 Brian Masney <masneyb@gftp.org>
masneyb
parents: 516
diff changeset
2549 break;
41
4bcfaf6307b5 2002-10-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
2550 }
4bcfaf6307b5 2002-10-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
2551
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
2552 if (errno == EINTR && request != NULL && request->cancel)
41
4bcfaf6307b5 2002-10-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
2553 {
4bcfaf6307b5 2002-10-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
2554 gftp_disconnect (request);
84
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 76
diff changeset
2555 return (GFTP_ERETRYABLE);
41
4bcfaf6307b5 2002-10-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
2556 }
4bcfaf6307b5 2002-10-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
2557
4bcfaf6307b5 2002-10-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
2558 return (ret);
4bcfaf6307b5 2002-10-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
2559 }
4bcfaf6307b5 2002-10-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
2560
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
2561
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
2562 ssize_t
168
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 151
diff changeset
2563 gftp_fd_write (gftp_request * request, const char *ptr, size_t size, int fd)
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
2564 {
325
0fcc6468a0af 2003-12-4 Brian Masney <masneyb@gftp.org>
masneyb
parents: 313
diff changeset
2565 intptr_t network_timeout;
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
2566 struct timeval tv;
248
16a967a4d003 2003-8-7 Brian Masney <masneyb@gftp.org>
masneyb
parents: 245
diff changeset
2567 ssize_t w_ret;
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
2568 fd_set fset;
516
fbb5a02beddb 2004-7-26 Brian Masney <masneyb@gftp.org>
masneyb
parents: 512
diff changeset
2569 int ret;
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
2570
122
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 107
diff changeset
2571 gftp_lookup_request_option (request, "network_timeout", &network_timeout);
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 107
diff changeset
2572
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
2573 errno = 0;
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
2574 ret = 0;
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
2575 do
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
2576 {
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
2577 FD_ZERO (&fset);
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
2578 FD_SET (fd, &fset);
122
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 107
diff changeset
2579 tv.tv_sec = network_timeout;
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
2580 tv.tv_usec = 0;
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
2581 ret = select (fd + 1, NULL, &fset, NULL, &tv);
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
2582 if (ret == -1 && errno == EINTR)
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
2583 {
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
2584 if (request != NULL && request->cancel)
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
2585 break;
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
2586 else
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
2587 continue;
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
2588 }
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
2589 else if (ret <= 0)
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
2590 {
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
2591 if (request != NULL)
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
2592 {
186
13ca1defdc75 2003-6-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 185
diff changeset
2593 request->logging_function (gftp_logging_error, request,
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
2594 _("Connection to %s timed out\n"),
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
2595 request->hostname);
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
2596 gftp_disconnect (request);
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
2597 }
84
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 76
diff changeset
2598 return (GFTP_ERETRYABLE);
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
2599 }
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
2600
248
16a967a4d003 2003-8-7 Brian Masney <masneyb@gftp.org>
masneyb
parents: 245
diff changeset
2601 w_ret = write (fd, ptr, size);
16a967a4d003 2003-8-7 Brian Masney <masneyb@gftp.org>
masneyb
parents: 245
diff changeset
2602 if (w_ret < 0)
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
2603 {
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
2604 if (errno == EINTR)
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
2605 {
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
2606 if (request != NULL && request->cancel)
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
2607 break;
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
2608 else
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
2609 continue;
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
2610 }
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
2611
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
2612 if (request != NULL)
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
2613 {
186
13ca1defdc75 2003-6-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 185
diff changeset
2614 request->logging_function (gftp_logging_error, request,
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
2615 _("Error: Could not write to socket: %s\n"),
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
2616 g_strerror (errno));
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
2617 gftp_disconnect (request);
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
2618 }
84
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 76
diff changeset
2619 return (GFTP_ERETRYABLE);
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
2620 }
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
2621
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
2622 ptr += w_ret;
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
2623 size -= w_ret;
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
2624 ret += w_ret;
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
2625 }
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
2626 while (size > 0);
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
2627
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
2628 if (errno == EINTR && request != NULL && request->cancel)
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
2629 {
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
2630 gftp_disconnect (request);
84
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 76
diff changeset
2631 return (GFTP_ERETRYABLE);
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
2632 }
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
2633
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
2634 return (ret);
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
2635 }
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
2636
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
2637
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
2638 ssize_t
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
2639 gftp_writefmt (gftp_request * request, int fd, const char *fmt, ...)
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
2640 {
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
2641 char *tempstr;
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
2642 va_list argp;
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
2643 ssize_t ret;
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
2644
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
2645 va_start (argp, fmt);
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
2646 tempstr = g_strdup_vprintf (fmt, argp);
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
2647 va_end (argp);
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
2648
168
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 151
diff changeset
2649 ret = request->write_function (request, tempstr, strlen (tempstr), fd);
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
2650 g_free (tempstr);
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
2651 return (ret);
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
2652 }
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
2653
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
2654
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
2655 int
168
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 151
diff changeset
2656 gftp_fd_set_sockblocking (gftp_request * request, int fd, int non_blocking)
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
2657 {
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
2658 int flags;
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
2659
84
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 76
diff changeset
2660 if ((flags = fcntl (fd, F_GETFL, 0)) < 0)
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
2661 {
186
13ca1defdc75 2003-6-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 185
diff changeset
2662 request->logging_function (gftp_logging_error, request,
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
2663 _("Cannot get socket flags: %s\n"),
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
2664 g_strerror (errno));
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
2665 gftp_disconnect (request);
84
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 76
diff changeset
2666 return (GFTP_ERETRYABLE);
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
2667 }
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
2668
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
2669 if (non_blocking)
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
2670 flags |= O_NONBLOCK;
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
2671 else
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
2672 flags &= ~O_NONBLOCK;
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
2673
84
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 76
diff changeset
2674 if (fcntl (fd, F_SETFL, flags) < 0)
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
2675 {
186
13ca1defdc75 2003-6-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 185
diff changeset
2676 request->logging_function (gftp_logging_error, request,
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
2677 _("Cannot set socket to non-blocking: %s\n"),
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
2678 g_strerror (errno));
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
2679 gftp_disconnect (request);
84
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 76
diff changeset
2680 return (GFTP_ERETRYABLE);
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
2681 }
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
2682
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
2683 return (0);
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
2684 }
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
2685
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
2686
63
41b71c4e5076 2002-11-2333 Brian Masney <masneyb@gftp.org>
masneyb
parents: 60
diff changeset
2687 void
41b71c4e5076 2002-11-2333 Brian Masney <masneyb@gftp.org>
masneyb
parents: 60
diff changeset
2688 gftp_swap_socks (gftp_request * dest, gftp_request * source)
41b71c4e5076 2002-11-2333 Brian Masney <masneyb@gftp.org>
masneyb
parents: 60
diff changeset
2689 {
41b71c4e5076 2002-11-2333 Brian Masney <masneyb@gftp.org>
masneyb
parents: 60
diff changeset
2690 g_return_if_fail (dest != NULL);
41b71c4e5076 2002-11-2333 Brian Masney <masneyb@gftp.org>
masneyb
parents: 60
diff changeset
2691 g_return_if_fail (source != NULL);
41b71c4e5076 2002-11-2333 Brian Masney <masneyb@gftp.org>
masneyb
parents: 60
diff changeset
2692 g_return_if_fail (dest->protonum == source->protonum);
41b71c4e5076 2002-11-2333 Brian Masney <masneyb@gftp.org>
masneyb
parents: 60
diff changeset
2693
41b71c4e5076 2002-11-2333 Brian Masney <masneyb@gftp.org>
masneyb
parents: 60
diff changeset
2694 dest->datafd = source->datafd;
41b71c4e5076 2002-11-2333 Brian Masney <masneyb@gftp.org>
masneyb
parents: 60
diff changeset
2695 dest->cached = 0;
397
14ef37b62c20 2004-2-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 381
diff changeset
2696 #ifdef USE_SSL
14ef37b62c20 2004-2-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 381
diff changeset
2697 dest->ssl = source->ssl;
14ef37b62c20 2004-2-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 381
diff changeset
2698 #endif
14ef37b62c20 2004-2-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 381
diff changeset
2699
63
41b71c4e5076 2002-11-2333 Brian Masney <masneyb@gftp.org>
masneyb
parents: 60
diff changeset
2700 if (!source->always_connected)
41b71c4e5076 2002-11-2333 Brian Masney <masneyb@gftp.org>
masneyb
parents: 60
diff changeset
2701 {
41b71c4e5076 2002-11-2333 Brian Masney <masneyb@gftp.org>
masneyb
parents: 60
diff changeset
2702 source->datafd = -1;
41b71c4e5076 2002-11-2333 Brian Masney <masneyb@gftp.org>
masneyb
parents: 60
diff changeset
2703 source->cached = 1;
397
14ef37b62c20 2004-2-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 381
diff changeset
2704 #ifdef USE_SSL
14ef37b62c20 2004-2-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 381
diff changeset
2705 source->ssl = NULL;
14ef37b62c20 2004-2-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 381
diff changeset
2706 #endif
63
41b71c4e5076 2002-11-2333 Brian Masney <masneyb@gftp.org>
masneyb
parents: 60
diff changeset
2707 }
41b71c4e5076 2002-11-2333 Brian Masney <masneyb@gftp.org>
masneyb
parents: 60
diff changeset
2708
516
fbb5a02beddb 2004-7-26 Brian Masney <masneyb@gftp.org>
masneyb
parents: 512
diff changeset
2709 if (dest->swap_socks != NULL)
63
41b71c4e5076 2002-11-2333 Brian Masney <masneyb@gftp.org>
masneyb
parents: 60
diff changeset
2710 dest->swap_socks (dest, source);
41b71c4e5076 2002-11-2333 Brian Masney <masneyb@gftp.org>
masneyb
parents: 60
diff changeset
2711 }
41b71c4e5076 2002-11-2333 Brian Masney <masneyb@gftp.org>
masneyb
parents: 60
diff changeset
2712
122
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 107
diff changeset
2713
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 107
diff changeset
2714 void
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 107
diff changeset
2715 gftp_calc_kbs (gftp_transfer * tdata, ssize_t num_read)
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 107
diff changeset
2716 {
469
2ad1916dc611 2004-5-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 463
diff changeset
2717 /* Needed for systems that size(float) < size(void *) */
2ad1916dc611 2004-5-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 463
diff changeset
2718 union { intptr_t i; float f; } maxkbs;
122
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 107
diff changeset
2719 unsigned long waitusecs;
220
6de9a8280aa4 2003-7-10 Brian Masney <masneyb@gftp.org>
masneyb
parents: 218
diff changeset
2720 double start_difftime;
122
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 107
diff changeset
2721 struct timeval tv;
222
007145d7d975 2003-7-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 220
diff changeset
2722 int waited;
122
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 107
diff changeset
2723
469
2ad1916dc611 2004-5-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 463
diff changeset
2724 gftp_lookup_request_option (tdata->fromreq, "maxkbs", &maxkbs.f);
122
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 107
diff changeset
2725
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 107
diff changeset
2726 if (g_thread_supported ())
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 107
diff changeset
2727 g_static_mutex_lock (&tdata->statmutex);
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 107
diff changeset
2728
220
6de9a8280aa4 2003-7-10 Brian Masney <masneyb@gftp.org>
masneyb
parents: 218
diff changeset
2729 gettimeofday (&tv, NULL);
6de9a8280aa4 2003-7-10 Brian Masney <masneyb@gftp.org>
masneyb
parents: 218
diff changeset
2730
122
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 107
diff changeset
2731 tdata->trans_bytes += num_read;
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 107
diff changeset
2732 tdata->curtrans += num_read;
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 107
diff changeset
2733 tdata->stalled = 0;
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 107
diff changeset
2734
220
6de9a8280aa4 2003-7-10 Brian Masney <masneyb@gftp.org>
masneyb
parents: 218
diff changeset
2735 start_difftime = (tv.tv_sec - tdata->starttime.tv_sec) + ((double) (tv.tv_usec - tdata->starttime.tv_usec) / 1000000.0);
6de9a8280aa4 2003-7-10 Brian Masney <masneyb@gftp.org>
masneyb
parents: 218
diff changeset
2736
6de9a8280aa4 2003-7-10 Brian Masney <masneyb@gftp.org>
masneyb
parents: 218
diff changeset
2737 if (start_difftime <= 0)
6de9a8280aa4 2003-7-10 Brian Masney <masneyb@gftp.org>
masneyb
parents: 218
diff changeset
2738 tdata->kbs = tdata->trans_bytes / 1024.0;
122
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 107
diff changeset
2739 else
220
6de9a8280aa4 2003-7-10 Brian Masney <masneyb@gftp.org>
masneyb
parents: 218
diff changeset
2740 tdata->kbs = tdata->trans_bytes / 1024.0 / start_difftime;
6de9a8280aa4 2003-7-10 Brian Masney <masneyb@gftp.org>
masneyb
parents: 218
diff changeset
2741
222
007145d7d975 2003-7-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 220
diff changeset
2742 waited = 0;
469
2ad1916dc611 2004-5-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 463
diff changeset
2743 if (maxkbs.f > 0 && tdata->kbs > maxkbs.f)
122
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 107
diff changeset
2744 {
469
2ad1916dc611 2004-5-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 463
diff changeset
2745 waitusecs = num_read / 1024.0 / maxkbs.f * 1000000.0 - start_difftime;
122
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 107
diff changeset
2746
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 107
diff changeset
2747 if (waitusecs > 0)
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 107
diff changeset
2748 {
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 107
diff changeset
2749 if (g_thread_supported ())
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 107
diff changeset
2750 g_static_mutex_unlock (&tdata->statmutex);
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 107
diff changeset
2751
222
007145d7d975 2003-7-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 220
diff changeset
2752 waited = 1;
122
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 107
diff changeset
2753 usleep (waitusecs);
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 107
diff changeset
2754
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 107
diff changeset
2755 if (g_thread_supported ())
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 107
diff changeset
2756 g_static_mutex_lock (&tdata->statmutex);
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 107
diff changeset
2757 }
222
007145d7d975 2003-7-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 220
diff changeset
2758
122
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 107
diff changeset
2759 }
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 107
diff changeset
2760
222
007145d7d975 2003-7-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 220
diff changeset
2761 if (waited)
007145d7d975 2003-7-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 220
diff changeset
2762 gettimeofday (&tdata->lasttime, NULL);
007145d7d975 2003-7-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 220
diff changeset
2763 else
007145d7d975 2003-7-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 220
diff changeset
2764 memcpy (&tdata->lasttime, &tv, sizeof (tdata->lasttime));
122
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 107
diff changeset
2765
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 107
diff changeset
2766 if (g_thread_supported ())
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 107
diff changeset
2767 g_static_mutex_unlock (&tdata->statmutex);
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 107
diff changeset
2768 }
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 107
diff changeset
2769
125
b875de05c22d 2003-4-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
2770
b875de05c22d 2003-4-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
2771 int
b875de05c22d 2003-4-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
2772 gftp_get_transfer_status (gftp_transfer * tdata, ssize_t num_read)
b875de05c22d 2003-4-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
2773 {
325
0fcc6468a0af 2003-12-4 Brian Masney <masneyb@gftp.org>
masneyb
parents: 313
diff changeset
2774 intptr_t retries, sleep_time;
125
b875de05c22d 2003-4-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
2775 gftp_file * tempfle;
b875de05c22d 2003-4-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
2776 struct timeval tv;
498
76c4e4cd108e 2004-7-12 Brian Masney <masneyb@gftp.org>
masneyb
parents: 485
diff changeset
2777 int ret1, ret2;
125
b875de05c22d 2003-4-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
2778
b875de05c22d 2003-4-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
2779 ret1 = ret2 = 0;
b875de05c22d 2003-4-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
2780 gftp_lookup_request_option (tdata->fromreq, "retries", &retries);
b875de05c22d 2003-4-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
2781 gftp_lookup_request_option (tdata->fromreq, "sleep_time", &sleep_time);
b875de05c22d 2003-4-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
2782
b875de05c22d 2003-4-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
2783 if (g_thread_supported ())
b875de05c22d 2003-4-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
2784 g_static_mutex_lock (&tdata->structmutex);
b875de05c22d 2003-4-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
2785
b875de05c22d 2003-4-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
2786 if (tdata->curfle == NULL)
b875de05c22d 2003-4-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
2787 {
b875de05c22d 2003-4-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
2788 if (g_thread_supported ())
b875de05c22d 2003-4-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
2789 g_static_mutex_unlock (&tdata->structmutex);
b875de05c22d 2003-4-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
2790
b875de05c22d 2003-4-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
2791 return (GFTP_EFATAL);
b875de05c22d 2003-4-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
2792 }
b875de05c22d 2003-4-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
2793
b875de05c22d 2003-4-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
2794 tempfle = tdata->curfle->data;
b875de05c22d 2003-4-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
2795
b875de05c22d 2003-4-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
2796 if (g_thread_supported ())
b875de05c22d 2003-4-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
2797 g_static_mutex_unlock (&tdata->structmutex);
b875de05c22d 2003-4-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
2798
b875de05c22d 2003-4-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
2799 gftp_disconnect (tdata->fromreq);
b875de05c22d 2003-4-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
2800 gftp_disconnect (tdata->toreq);
b875de05c22d 2003-4-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
2801
b875de05c22d 2003-4-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
2802 if (num_read < 0 || tdata->skip_file)
b875de05c22d 2003-4-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
2803 {
b875de05c22d 2003-4-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
2804 if (num_read == GFTP_EFATAL)
b875de05c22d 2003-4-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
2805 return (GFTP_EFATAL);
512
2c8a42a63a31 2004-7-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 509
diff changeset
2806 else if (num_read != GFTP_ETIMEDOUT && !tdata->conn_error_no_timeout)
125
b875de05c22d 2003-4-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
2807 {
303
3b9d5797050f 2003-11-2 Brian Masney <masneyb@gftp.org>
masneyb
parents: 294
diff changeset
2808 if (retries != 0 &&
3b9d5797050f 2003-11-2 Brian Masney <masneyb@gftp.org>
masneyb
parents: 294
diff changeset
2809 tdata->current_file_retries >= retries)
3b9d5797050f 2003-11-2 Brian Masney <masneyb@gftp.org>
masneyb
parents: 294
diff changeset
2810 {
3b9d5797050f 2003-11-2 Brian Masney <masneyb@gftp.org>
masneyb
parents: 294
diff changeset
2811 tdata->fromreq->logging_function (gftp_logging_error, tdata->fromreq,
3b9d5797050f 2003-11-2 Brian Masney <masneyb@gftp.org>
masneyb
parents: 294
diff changeset
2812 _("Error: Remote site %s disconnected. Max retries reached...giving up\n"),
3b9d5797050f 2003-11-2 Brian Masney <masneyb@gftp.org>
masneyb
parents: 294
diff changeset
2813 tdata->fromreq->hostname != NULL ?
3b9d5797050f 2003-11-2 Brian Masney <masneyb@gftp.org>
masneyb
parents: 294
diff changeset
2814 tdata->fromreq->hostname : tdata->toreq->hostname);
3b9d5797050f 2003-11-2 Brian Masney <masneyb@gftp.org>
masneyb
parents: 294
diff changeset
2815 return (GFTP_EFATAL);
3b9d5797050f 2003-11-2 Brian Masney <masneyb@gftp.org>
masneyb
parents: 294
diff changeset
2816 }
3b9d5797050f 2003-11-2 Brian Masney <masneyb@gftp.org>
masneyb
parents: 294
diff changeset
2817 else
3b9d5797050f 2003-11-2 Brian Masney <masneyb@gftp.org>
masneyb
parents: 294
diff changeset
2818 {
3b9d5797050f 2003-11-2 Brian Masney <masneyb@gftp.org>
masneyb
parents: 294
diff changeset
2819 tdata->fromreq->logging_function (gftp_logging_error, tdata->fromreq,
3b9d5797050f 2003-11-2 Brian Masney <masneyb@gftp.org>
masneyb
parents: 294
diff changeset
2820 _("Error: Remote site %s disconnected. Will reconnect in %d seconds\n"),
3b9d5797050f 2003-11-2 Brian Masney <masneyb@gftp.org>
masneyb
parents: 294
diff changeset
2821 tdata->fromreq->hostname != NULL ?
3b9d5797050f 2003-11-2 Brian Masney <masneyb@gftp.org>
masneyb
parents: 294
diff changeset
2822 tdata->fromreq->hostname : tdata->toreq->hostname,
3b9d5797050f 2003-11-2 Brian Masney <masneyb@gftp.org>
masneyb
parents: 294
diff changeset
2823 sleep_time);
3b9d5797050f 2003-11-2 Brian Masney <masneyb@gftp.org>
masneyb
parents: 294
diff changeset
2824 }
125
b875de05c22d 2003-4-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
2825 }
b875de05c22d 2003-4-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
2826
b875de05c22d 2003-4-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
2827 while (retries == 0 ||
b875de05c22d 2003-4-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
2828 tdata->current_file_retries <= retries)
b875de05c22d 2003-4-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
2829 {
512
2c8a42a63a31 2004-7-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 509
diff changeset
2830 if (num_read != GFTP_ETIMEDOUT && !tdata->conn_error_no_timeout &&
2c8a42a63a31 2004-7-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 509
diff changeset
2831 !tdata->skip_file)
125
b875de05c22d 2003-4-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
2832 {
b875de05c22d 2003-4-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
2833 tv.tv_sec = sleep_time;
b875de05c22d 2003-4-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
2834 tv.tv_usec = 0;
498
76c4e4cd108e 2004-7-12 Brian Masney <masneyb@gftp.org>
masneyb
parents: 485
diff changeset
2835
76c4e4cd108e 2004-7-12 Brian Masney <masneyb@gftp.org>
masneyb
parents: 485
diff changeset
2836 do
76c4e4cd108e 2004-7-12 Brian Masney <masneyb@gftp.org>
masneyb
parents: 485
diff changeset
2837 {
76c4e4cd108e 2004-7-12 Brian Masney <masneyb@gftp.org>
masneyb
parents: 485
diff changeset
2838 ret1 = select (0, NULL, NULL, NULL, &tv);
76c4e4cd108e 2004-7-12 Brian Masney <masneyb@gftp.org>
masneyb
parents: 485
diff changeset
2839 }
76c4e4cd108e 2004-7-12 Brian Masney <masneyb@gftp.org>
masneyb
parents: 485
diff changeset
2840 while (ret1 == -1 && errno == EINTR);
125
b875de05c22d 2003-4-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
2841 }
b875de05c22d 2003-4-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
2842
b875de05c22d 2003-4-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
2843 if ((ret1 = gftp_connect (tdata->fromreq)) == 0 &&
b875de05c22d 2003-4-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
2844 (ret2 = gftp_connect (tdata->toreq)) == 0)
b875de05c22d 2003-4-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
2845 {
b875de05c22d 2003-4-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
2846 if (g_thread_supported ())
b875de05c22d 2003-4-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
2847 g_static_mutex_lock (&tdata->structmutex);
b875de05c22d 2003-4-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
2848
b875de05c22d 2003-4-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
2849 tdata->resumed_bytes = tdata->resumed_bytes + tdata->trans_bytes - tdata->curresumed - tdata->curtrans;
b875de05c22d 2003-4-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
2850 tdata->trans_bytes = 0;
b875de05c22d 2003-4-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
2851 if (tdata->skip_file)
b875de05c22d 2003-4-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
2852 {
b875de05c22d 2003-4-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
2853 tdata->total_bytes -= tempfle->size;
b875de05c22d 2003-4-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
2854 tdata->curtrans = 0;
b875de05c22d 2003-4-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
2855
b875de05c22d 2003-4-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
2856 tdata->curfle = tdata->curfle->next;
b875de05c22d 2003-4-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
2857 tdata->next_file = 1;
b875de05c22d 2003-4-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
2858 tdata->skip_file = 0;
b875de05c22d 2003-4-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
2859 tdata->cancel = 0;
b875de05c22d 2003-4-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
2860 tdata->fromreq->cancel = 0;
b875de05c22d 2003-4-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
2861 tdata->toreq->cancel = 0;
b875de05c22d 2003-4-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
2862 }
b875de05c22d 2003-4-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
2863 else
b875de05c22d 2003-4-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
2864 {
b875de05c22d 2003-4-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
2865 tempfle->transfer_action = GFTP_TRANS_ACTION_RESUME;
b875de05c22d 2003-4-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
2866 tempfle->startsize = tdata->curtrans + tdata->curresumed;
b875de05c22d 2003-4-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
2867 /* We decrement this here because it will be incremented in
b875de05c22d 2003-4-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
2868 the loop again */
b875de05c22d 2003-4-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
2869 tdata->curresumed = 0;
b875de05c22d 2003-4-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
2870 tdata->current_file_number--; /* Decrement this because it
b875de05c22d 2003-4-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
2871 will be incremented when we
b875de05c22d 2003-4-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
2872 continue in the loop */
b875de05c22d 2003-4-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
2873 }
b875de05c22d 2003-4-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
2874
b875de05c22d 2003-4-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
2875 gettimeofday (&tdata->starttime, NULL);
b875de05c22d 2003-4-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
2876
b875de05c22d 2003-4-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
2877 if (g_thread_supported ())
b875de05c22d 2003-4-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
2878 g_static_mutex_unlock (&tdata->structmutex);
b875de05c22d 2003-4-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
2879
b875de05c22d 2003-4-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
2880 return (GFTP_ERETRYABLE);
b875de05c22d 2003-4-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
2881 }
b875de05c22d 2003-4-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
2882 else if (ret1 == GFTP_EFATAL || ret2 == GFTP_EFATAL)
b875de05c22d 2003-4-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
2883 {
b875de05c22d 2003-4-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
2884 gftp_disconnect (tdata->fromreq);
b875de05c22d 2003-4-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
2885 gftp_disconnect (tdata->toreq);
b875de05c22d 2003-4-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
2886 return (GFTP_EFATAL);
b875de05c22d 2003-4-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
2887 }
b875de05c22d 2003-4-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
2888 else
b875de05c22d 2003-4-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
2889 tdata->current_file_retries++;
b875de05c22d 2003-4-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
2890 }
b875de05c22d 2003-4-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
2891 }
b875de05c22d 2003-4-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
2892 else if (tdata->cancel)
b875de05c22d 2003-4-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
2893 return (GFTP_EFATAL);
b875de05c22d 2003-4-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
2894
b875de05c22d 2003-4-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
2895 return (0);
b875de05c22d 2003-4-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
2896 }
b875de05c22d 2003-4-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
2897
182
33b394ebba68 2003-6-15 Brian Masney <masneyb@gftp.org>
masneyb
parents: 179
diff changeset
2898
33b394ebba68 2003-6-15 Brian Masney <masneyb@gftp.org>
masneyb
parents: 179
diff changeset
2899 int
33b394ebba68 2003-6-15 Brian Masney <masneyb@gftp.org>
masneyb
parents: 179
diff changeset
2900 gftp_fd_open (gftp_request * request, const char *pathname, int flags, mode_t mode)
33b394ebba68 2003-6-15 Brian Masney <masneyb@gftp.org>
masneyb
parents: 179
diff changeset
2901 {
33b394ebba68 2003-6-15 Brian Masney <masneyb@gftp.org>
masneyb
parents: 179
diff changeset
2902 int fd;
33b394ebba68 2003-6-15 Brian Masney <masneyb@gftp.org>
masneyb
parents: 179
diff changeset
2903
227
a85a097bbb02 2003-7-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 222
diff changeset
2904 if (mode == 0)
a85a097bbb02 2003-7-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 222
diff changeset
2905 fd = open (pathname, flags);
a85a097bbb02 2003-7-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 222
diff changeset
2906 else
a85a097bbb02 2003-7-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 222
diff changeset
2907 fd = open (pathname, flags, mode);
a85a097bbb02 2003-7-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 222
diff changeset
2908
a85a097bbb02 2003-7-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 222
diff changeset
2909 if (fd < 0)
182
33b394ebba68 2003-6-15 Brian Masney <masneyb@gftp.org>
masneyb
parents: 179
diff changeset
2910 {
33b394ebba68 2003-6-15 Brian Masney <masneyb@gftp.org>
masneyb
parents: 179
diff changeset
2911 if (request != NULL)
186
13ca1defdc75 2003-6-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 185
diff changeset
2912 request->logging_function (gftp_logging_error, request,
182
33b394ebba68 2003-6-15 Brian Masney <masneyb@gftp.org>
masneyb
parents: 179
diff changeset
2913 _("Error: Cannot open local file %s: %s\n"),
33b394ebba68 2003-6-15 Brian Masney <masneyb@gftp.org>
masneyb
parents: 179
diff changeset
2914 pathname, g_strerror (errno));
33b394ebba68 2003-6-15 Brian Masney <masneyb@gftp.org>
masneyb
parents: 179
diff changeset
2915 return (GFTP_ERETRYABLE);
33b394ebba68 2003-6-15 Brian Masney <masneyb@gftp.org>
masneyb
parents: 179
diff changeset
2916 }
33b394ebba68 2003-6-15 Brian Masney <masneyb@gftp.org>
masneyb
parents: 179
diff changeset
2917
33b394ebba68 2003-6-15 Brian Masney <masneyb@gftp.org>
masneyb
parents: 179
diff changeset
2918 if (fcntl (fd, F_SETFD, 1) == -1)
33b394ebba68 2003-6-15 Brian Masney <masneyb@gftp.org>
masneyb
parents: 179
diff changeset
2919 {
33b394ebba68 2003-6-15 Brian Masney <masneyb@gftp.org>
masneyb
parents: 179
diff changeset
2920 if (request != NULL)
186
13ca1defdc75 2003-6-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 185
diff changeset
2921 request->logging_function (gftp_logging_error, request,
182
33b394ebba68 2003-6-15 Brian Masney <masneyb@gftp.org>
masneyb
parents: 179
diff changeset
2922 _("Error: Cannot set close on exec flag: %s\n"),
33b394ebba68 2003-6-15 Brian Masney <masneyb@gftp.org>
masneyb
parents: 179
diff changeset
2923 g_strerror (errno));
33b394ebba68 2003-6-15 Brian Masney <masneyb@gftp.org>
masneyb
parents: 179
diff changeset
2924
33b394ebba68 2003-6-15 Brian Masney <masneyb@gftp.org>
masneyb
parents: 179
diff changeset
2925 return (-1);
33b394ebba68 2003-6-15 Brian Masney <masneyb@gftp.org>
masneyb
parents: 179
diff changeset
2926 }
33b394ebba68 2003-6-15 Brian Masney <masneyb@gftp.org>
masneyb
parents: 179
diff changeset
2927
33b394ebba68 2003-6-15 Brian Masney <masneyb@gftp.org>
masneyb
parents: 179
diff changeset
2928 return (fd);
33b394ebba68 2003-6-15 Brian Masney <masneyb@gftp.org>
masneyb
parents: 179
diff changeset
2929 }
422
38bfc112ab46 2004-3-14 Brian Masney <masneyb@gftp.org>
masneyb
parents: 397
diff changeset
2930
38bfc112ab46 2004-3-14 Brian Masney <masneyb@gftp.org>
masneyb
parents: 397
diff changeset
2931
38bfc112ab46 2004-3-14 Brian Masney <masneyb@gftp.org>
masneyb
parents: 397
diff changeset
2932 void
38bfc112ab46 2004-3-14 Brian Masney <masneyb@gftp.org>
masneyb
parents: 397
diff changeset
2933 gftp_setup_startup_directory (gftp_request * request)
38bfc112ab46 2004-3-14 Brian Masney <masneyb@gftp.org>
masneyb
parents: 397
diff changeset
2934 {
38bfc112ab46 2004-3-14 Brian Masney <masneyb@gftp.org>
masneyb
parents: 397
diff changeset
2935 char *startup_directory, *tempstr;
38bfc112ab46 2004-3-14 Brian Masney <masneyb@gftp.org>
masneyb
parents: 397
diff changeset
2936
38bfc112ab46 2004-3-14 Brian Masney <masneyb@gftp.org>
masneyb
parents: 397
diff changeset
2937 gftp_lookup_request_option (request, "startup_directory", &startup_directory);
38bfc112ab46 2004-3-14 Brian Masney <masneyb@gftp.org>
masneyb
parents: 397
diff changeset
2938
38bfc112ab46 2004-3-14 Brian Masney <masneyb@gftp.org>
masneyb
parents: 397
diff changeset
2939 if (*startup_directory != '\0' &&
38bfc112ab46 2004-3-14 Brian Masney <masneyb@gftp.org>
masneyb
parents: 397
diff changeset
2940 (tempstr = expand_path (startup_directory)) != NULL)
38bfc112ab46 2004-3-14 Brian Masney <masneyb@gftp.org>
masneyb
parents: 397
diff changeset
2941 {
38bfc112ab46 2004-3-14 Brian Masney <masneyb@gftp.org>
masneyb
parents: 397
diff changeset
2942 gftp_set_directory (request, tempstr);
38bfc112ab46 2004-3-14 Brian Masney <masneyb@gftp.org>
masneyb
parents: 397
diff changeset
2943 g_free (tempstr);
38bfc112ab46 2004-3-14 Brian Masney <masneyb@gftp.org>
masneyb
parents: 397
diff changeset
2944 }
38bfc112ab46 2004-3-14 Brian Masney <masneyb@gftp.org>
masneyb
parents: 397
diff changeset
2945 }
38bfc112ab46 2004-3-14 Brian Masney <masneyb@gftp.org>
masneyb
parents: 397
diff changeset
2946
499
39e9945288ea 2004-7-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 498
diff changeset
2947
39e9945288ea 2004-7-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 498
diff changeset
2948 char *
39e9945288ea 2004-7-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 498
diff changeset
2949 gftp_convert_attributes_from_mode_t (mode_t mode)
39e9945288ea 2004-7-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 498
diff changeset
2950 {
39e9945288ea 2004-7-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 498
diff changeset
2951 char *str;
39e9945288ea 2004-7-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 498
diff changeset
2952
39e9945288ea 2004-7-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 498
diff changeset
2953 str = g_malloc0 (11);
39e9945288ea 2004-7-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 498
diff changeset
2954
39e9945288ea 2004-7-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 498
diff changeset
2955 str[0] = '?';
39e9945288ea 2004-7-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 498
diff changeset
2956 if (S_ISREG (mode))
39e9945288ea 2004-7-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 498
diff changeset
2957 str[0] = '-';
39e9945288ea 2004-7-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 498
diff changeset
2958
39e9945288ea 2004-7-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 498
diff changeset
2959 if (S_ISLNK (mode))
39e9945288ea 2004-7-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 498
diff changeset
2960 str[0] = 'l';
39e9945288ea 2004-7-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 498
diff changeset
2961
39e9945288ea 2004-7-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 498
diff changeset
2962 if (S_ISBLK (mode))
39e9945288ea 2004-7-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 498
diff changeset
2963 str[0] = 'b';
39e9945288ea 2004-7-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 498
diff changeset
2964
39e9945288ea 2004-7-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 498
diff changeset
2965 if (S_ISCHR (mode))
39e9945288ea 2004-7-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 498
diff changeset
2966 str[0] = 'c';
39e9945288ea 2004-7-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 498
diff changeset
2967
39e9945288ea 2004-7-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 498
diff changeset
2968 if (S_ISFIFO (mode))
39e9945288ea 2004-7-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 498
diff changeset
2969 str[0] = 'p';
39e9945288ea 2004-7-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 498
diff changeset
2970
39e9945288ea 2004-7-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 498
diff changeset
2971 if (S_ISSOCK (mode))
39e9945288ea 2004-7-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 498
diff changeset
2972 str[0] = 's';
39e9945288ea 2004-7-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 498
diff changeset
2973
39e9945288ea 2004-7-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 498
diff changeset
2974 if (S_ISDIR (mode))
39e9945288ea 2004-7-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 498
diff changeset
2975 str[0] = 'd';
39e9945288ea 2004-7-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 498
diff changeset
2976
39e9945288ea 2004-7-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 498
diff changeset
2977 str[1] = mode & S_IRUSR ? 'r' : '-';
39e9945288ea 2004-7-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 498
diff changeset
2978 str[2] = mode & S_IWUSR ? 'w' : '-';
39e9945288ea 2004-7-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 498
diff changeset
2979
39e9945288ea 2004-7-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 498
diff changeset
2980 if ((mode & S_ISUID) && (mode & S_IXUSR))
39e9945288ea 2004-7-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 498
diff changeset
2981 str[3] = 's';
39e9945288ea 2004-7-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 498
diff changeset
2982 else if (mode & S_ISUID)
39e9945288ea 2004-7-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 498
diff changeset
2983 str[3] = 'S';
39e9945288ea 2004-7-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 498
diff changeset
2984 else if (mode & S_IXUSR)
39e9945288ea 2004-7-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 498
diff changeset
2985 str[3] = 'x';
39e9945288ea 2004-7-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 498
diff changeset
2986 else
39e9945288ea 2004-7-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 498
diff changeset
2987 str[3] = '-';
39e9945288ea 2004-7-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 498
diff changeset
2988
39e9945288ea 2004-7-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 498
diff changeset
2989 str[4] = mode & S_IRGRP ? 'r' : '-';
39e9945288ea 2004-7-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 498
diff changeset
2990 str[5] = mode & S_IWGRP ? 'w' : '-';
39e9945288ea 2004-7-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 498
diff changeset
2991
39e9945288ea 2004-7-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 498
diff changeset
2992 if ((mode & S_ISGID) && (mode & S_IXGRP))
39e9945288ea 2004-7-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 498
diff changeset
2993 str[6] = 's';
39e9945288ea 2004-7-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 498
diff changeset
2994 else if (mode & S_ISGID)
39e9945288ea 2004-7-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 498
diff changeset
2995 str[6] = 'S';
39e9945288ea 2004-7-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 498
diff changeset
2996 else if (mode & S_IXGRP)
39e9945288ea 2004-7-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 498
diff changeset
2997 str[6] = 'x';
39e9945288ea 2004-7-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 498
diff changeset
2998 else
39e9945288ea 2004-7-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 498
diff changeset
2999 str[6] = '-';
39e9945288ea 2004-7-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 498
diff changeset
3000
39e9945288ea 2004-7-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 498
diff changeset
3001 str[7] = mode & S_IROTH ? 'r' : '-';
39e9945288ea 2004-7-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 498
diff changeset
3002 str[8] = mode & S_IWOTH ? 'w' : '-';
39e9945288ea 2004-7-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 498
diff changeset
3003
39e9945288ea 2004-7-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 498
diff changeset
3004 if ((mode & S_ISVTX) && (mode & S_IXOTH))
39e9945288ea 2004-7-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 498
diff changeset
3005 str[9] = 't';
39e9945288ea 2004-7-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 498
diff changeset
3006 else if (mode & S_ISVTX)
39e9945288ea 2004-7-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 498
diff changeset
3007 str[9] = 'T';
39e9945288ea 2004-7-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 498
diff changeset
3008 else if (mode & S_IXOTH)
39e9945288ea 2004-7-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 498
diff changeset
3009 str[9] = 'x';
39e9945288ea 2004-7-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 498
diff changeset
3010 else
39e9945288ea 2004-7-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 498
diff changeset
3011 str[9] = '-';
39e9945288ea 2004-7-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 498
diff changeset
3012
39e9945288ea 2004-7-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 498
diff changeset
3013 return (str);
39e9945288ea 2004-7-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 498
diff changeset
3014 }
39e9945288ea 2004-7-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 498
diff changeset
3015
39e9945288ea 2004-7-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 498
diff changeset
3016
39e9945288ea 2004-7-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 498
diff changeset
3017 mode_t
39e9945288ea 2004-7-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 498
diff changeset
3018 gftp_convert_attributes_to_mode_t (char *attribs)
39e9945288ea 2004-7-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 498
diff changeset
3019 {
39e9945288ea 2004-7-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 498
diff changeset
3020 mode_t mode;
39e9945288ea 2004-7-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 498
diff changeset
3021
39e9945288ea 2004-7-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 498
diff changeset
3022 if (attribs[0] == 'd')
39e9945288ea 2004-7-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 498
diff changeset
3023 mode = S_IFDIR;
39e9945288ea 2004-7-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 498
diff changeset
3024 else if (attribs[0] == 'l')
39e9945288ea 2004-7-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 498
diff changeset
3025 mode = S_IFLNK;
39e9945288ea 2004-7-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 498
diff changeset
3026 else if (attribs[0] == 's')
39e9945288ea 2004-7-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 498
diff changeset
3027 mode = S_IFSOCK;
39e9945288ea 2004-7-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 498
diff changeset
3028 else if (attribs[0] == 'b')
39e9945288ea 2004-7-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 498
diff changeset
3029 mode = S_IFBLK;
39e9945288ea 2004-7-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 498
diff changeset
3030 else if (attribs[0] == 'c')
39e9945288ea 2004-7-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 498
diff changeset
3031 mode = S_IFCHR;
39e9945288ea 2004-7-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 498
diff changeset
3032 else
39e9945288ea 2004-7-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 498
diff changeset
3033 mode = S_IFREG;
39e9945288ea 2004-7-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 498
diff changeset
3034
39e9945288ea 2004-7-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 498
diff changeset
3035 if (attribs[1] == 'r')
39e9945288ea 2004-7-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 498
diff changeset
3036 mode |= S_IRUSR;
39e9945288ea 2004-7-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 498
diff changeset
3037 if (attribs[2] == 'w')
39e9945288ea 2004-7-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 498
diff changeset
3038 mode |= S_IWUSR;
39e9945288ea 2004-7-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 498
diff changeset
3039 if (attribs[3] == 'x' || attribs[3] == 's')
39e9945288ea 2004-7-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 498
diff changeset
3040 mode |= S_IXUSR;
39e9945288ea 2004-7-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 498
diff changeset
3041 if (attribs[3] == 's' || attribs[3] == 'S')
39e9945288ea 2004-7-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 498
diff changeset
3042 mode |= S_ISUID;
39e9945288ea 2004-7-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 498
diff changeset
3043
39e9945288ea 2004-7-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 498
diff changeset
3044 if (attribs[4] == 'r')
39e9945288ea 2004-7-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 498
diff changeset
3045 mode |= S_IRGRP;
39e9945288ea 2004-7-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 498
diff changeset
3046 if (attribs[5] == 'w')
39e9945288ea 2004-7-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 498
diff changeset
3047 mode |= S_IWGRP;
39e9945288ea 2004-7-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 498
diff changeset
3048 if (attribs[6] == 'x' ||
39e9945288ea 2004-7-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 498
diff changeset
3049 attribs[6] == 's')
39e9945288ea 2004-7-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 498
diff changeset
3050 mode |= S_IXGRP;
39e9945288ea 2004-7-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 498
diff changeset
3051 if (attribs[6] == 's' || attribs[6] == 'S')
39e9945288ea 2004-7-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 498
diff changeset
3052 mode |= S_ISGID;
39e9945288ea 2004-7-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 498
diff changeset
3053
39e9945288ea 2004-7-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 498
diff changeset
3054 if (attribs[7] == 'r')
39e9945288ea 2004-7-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 498
diff changeset
3055 mode |= S_IROTH;
39e9945288ea 2004-7-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 498
diff changeset
3056 if (attribs[8] == 'w')
39e9945288ea 2004-7-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 498
diff changeset
3057 mode |= S_IWOTH;
39e9945288ea 2004-7-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 498
diff changeset
3058 if (attribs[9] == 'x' ||
39e9945288ea 2004-7-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 498
diff changeset
3059 attribs[9] == 's')
39e9945288ea 2004-7-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 498
diff changeset
3060 mode |= S_IXOTH;
39e9945288ea 2004-7-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 498
diff changeset
3061 if (attribs[9] == 't' || attribs[9] == 'T')
39e9945288ea 2004-7-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 498
diff changeset
3062 mode |= S_ISVTX;
39e9945288ea 2004-7-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 498
diff changeset
3063
39e9945288ea 2004-7-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 498
diff changeset
3064 return (mode);
39e9945288ea 2004-7-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 498
diff changeset
3065 }
39e9945288ea 2004-7-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 498
diff changeset
3066