annotate lib/protocols.c @ 349:3fccdc9eb16f

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