annotate lib/protocols.c @ 46:3da7765bc439

2002-10-31 Brian Masney <masneyb@gftp.org> * lib/protocols.c (gftp_get_next_file) - don't use g_filename_to_utf8. If g_locale_to_utf8 fails, print out a warning to the user on the console
author masneyb
date Fri, 01 Nov 2002 00:10:08 +0000
parents 311e29c40ed6
children e5f6054590b5
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 */
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
3 /* Copyright (C) 1998-2002 Brian Masney <masneyb@gftp.org> */
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 static time_t parse_time ( char **str );
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
24 static int gftp_parse_ls_eplf ( char *str,
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
25 gftp_file * fle );
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
26 static int gftp_parse_ls_unix ( char *str,
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
27 int cols,
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
28 gftp_file * fle );
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
29 static int gftp_parse_ls_nt ( char *str,
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
30 gftp_file * fle );
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
31 static int gftp_parse_ls_novell ( char *str,
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
32 gftp_file * fle );
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
33 static char *copy_token ( char **dest,
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
34 char *source );
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
35 static char *goto_next_token ( char *pos );
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
36 static GList * gftp_get_dir_listing ( gftp_transfer * transfer,
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
37 int getothdir );
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
38 static GHashTable * gftp_gen_dir_hash ( gftp_request * request );
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
39 static void gftp_destroy_dir_hash ( GHashTable * dirhash );
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
40 static void destroy_hash_ent ( gpointer key,
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
41 gpointer value,
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
42 gpointer user_data );
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
43
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
44 gftp_request *
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
45 gftp_request_new (void)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
46 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
47 gftp_request *request;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
48
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
49 request = g_malloc0 (sizeof (*request));
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
50 request->sockfd = NULL;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
51 request->datafd = NULL;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
52 request->data_type = GFTP_TYPE_BINARY;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
53 return (request);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
54 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
55
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
56
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
57 void
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
58 gftp_request_destroy (gftp_request * request)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
59 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
60 g_return_if_fail (request != NULL);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
61
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
62 gftp_disconnect (request);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
63
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
64 if (request->destroy != NULL)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
65 request->destroy (request);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
66
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
67 if (request->hostname)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
68 g_free (request->hostname);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
69 if (request->username)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
70 g_free (request->username);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
71 if (request->password)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
72 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
73 memset (request->password, 0, strlen (request->password));
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
74 g_free (request->password);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
75 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
76 if (request->account)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
77 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
78 memset (request->account, 0, strlen (request->account));
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
79 g_free (request->account);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
80 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
81 if (request->directory)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
82 g_free (request->directory);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
83 if (request->proxy_config)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
84 g_free (request->proxy_config);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
85 if (request->proxy_hostname)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
86 g_free (request->proxy_hostname);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
87 if (request->proxy_username)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
88 g_free (request->proxy_username);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
89 if (request->proxy_password)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
90 g_free (request->proxy_password);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
91 if (request->proxy_account)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
92 g_free (request->proxy_account);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
93 if (request->last_ftp_response)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
94 g_free (request->last_ftp_response);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
95 if (request->protocol_data)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
96 g_free (request->protocol_data);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
97 if (request->sftpserv_path)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
98 g_free (request->sftpserv_path);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
99 memset (request, 0, sizeof (*request));
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
100 g_free (request);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
101 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
102
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
103
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
104 void
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
105 gftp_file_destroy (gftp_file * file)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
106 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
107 g_return_if_fail (file != NULL);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
108
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
109 if (file->file)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
110 g_free (file->file);
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 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
126 g_return_val_if_fail (request != NULL, -2);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
127
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
128 if (request->connect == NULL)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
129 return (-2);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
130
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
131 if (request->sftpserv_path == NULL)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
132 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
133 switch (request->protonum)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
134 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
135 case GFTP_SSH_NUM:
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
136 request->sftpserv_path = g_strconcat (ssh1_sftp_path, NULL);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
137 break;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
138 case GFTP_SSHV2_NUM:
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
139 request->sftpserv_path = g_strconcat (ssh2_sftp_path, NULL);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
140 break;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
141 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
142 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
143
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
144 gftp_set_config_options (request);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
145
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
146 return (request->connect (request));
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
147 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
148
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
149
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
150 void
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
151 gftp_disconnect (gftp_request * request)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
152 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
153 g_return_if_fail (request != NULL);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
154
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
155 #if defined (HAVE_GETADDRINFO) && defined (HAVE_GAI_STRERROR)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
156 if (request->hostp)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
157 freeaddrinfo (request->hostp);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
158 #endif
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
159 request->hostp = NULL;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
160
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
161 if (request->sftpserv_path != NULL)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
162 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
163 g_free (request->sftpserv_path);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
164 request->sftpserv_path = NULL;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
165 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
166
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
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
174 size_t
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
175 gftp_get_file (gftp_request * request, const char *filename, FILE * fd,
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
176 size_t startsize)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
177 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
178 g_return_val_if_fail (request != NULL, -2);
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)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
182 return (-2);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
183 return (request->get_file (request, filename, fd, startsize));
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
184 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
185
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
186
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
187 int
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
188 gftp_put_file (gftp_request * request, const char *filename, FILE * fd,
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
189 size_t startsize, size_t totalsize)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
190 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
191 g_return_val_if_fail (request != NULL, -2);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
192
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
193 request->cached = 0;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
194 if (request->put_file == NULL)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
195 return (-2);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
196 return (request->put_file (request, filename, fd, startsize, totalsize));
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
197 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
198
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
199
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
200 long
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
201 gftp_transfer_file (gftp_request * fromreq, const char *fromfile,
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
202 FILE * fromfd, size_t fromsize,
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
203 gftp_request * toreq, const char *tofile,
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
204 FILE * tofd, size_t tosize)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
205 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
206 long size;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
207
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
208 g_return_val_if_fail (fromreq != NULL, -2);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
209 g_return_val_if_fail (fromfile != NULL, -2);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
210 g_return_val_if_fail (toreq != NULL, -2);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
211 g_return_val_if_fail (tofile != NULL, -2);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
212
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
213 if (strcmp (fromreq->protocol_name, toreq->protocol_name) == 0)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
214 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
215 if (fromreq->transfer_file == NULL)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
216 return (-2);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
217 return (fromreq->transfer_file (fromreq, fromfile, fromsize, toreq,
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
218 tofile, tosize));
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
219 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
220
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
221 fromreq->cached = 0;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
222 toreq->cached = 0;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
223 if ((size = gftp_get_file (fromreq, fromfile, fromfd, tosize)) < 0)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
224 return (-2);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
225
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
226 if (gftp_put_file (toreq, tofile, tofd, tosize, size) != 0)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
227 {
40
66c064fd05bc 2002-10-17 Brian Masney <masneyb@gftp.org>
masneyb
parents: 39
diff changeset
228 if (gftp_abort_transfer (fromreq) != 0)
66c064fd05bc 2002-10-17 Brian Masney <masneyb@gftp.org>
masneyb
parents: 39
diff changeset
229 gftp_end_transfer (fromreq);
66c064fd05bc 2002-10-17 Brian Masney <masneyb@gftp.org>
masneyb
parents: 39
diff changeset
230
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
231 return (-2);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
232 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
233
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
234 return (size);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
235 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
236
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
237
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
238 size_t
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
239 gftp_get_next_file_chunk (gftp_request * request, char *buf, size_t size)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
240 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
241 struct timeval tv;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
242 fd_set fset;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
243 size_t len;
41
4bcfaf6307b5 2002-10-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
244 int ret;
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
245
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
246 g_return_val_if_fail (request != NULL, -2);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
247 g_return_val_if_fail (buf != NULL, -2);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
248
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
249 if (request->get_next_file_chunk != NULL)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
250 return (request->get_next_file_chunk (request, buf, size));
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
251
41
4bcfaf6307b5 2002-10-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
252 errno = 0;
4bcfaf6307b5 2002-10-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
253 len = 0;
4bcfaf6307b5 2002-10-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
254 do
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
255 {
41
4bcfaf6307b5 2002-10-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
256 FD_ZERO (&fset);
4bcfaf6307b5 2002-10-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
257 FD_SET (fileno (request->datafd), &fset);
4bcfaf6307b5 2002-10-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
258 tv.tv_sec = request->network_timeout;
4bcfaf6307b5 2002-10-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
259 tv.tv_usec = 0;
4bcfaf6307b5 2002-10-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
260 ret = select (fileno (request->datafd) + 1, &fset, NULL, NULL, &tv);
4bcfaf6307b5 2002-10-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
261 if (ret == -1 && errno == EINTR)
4bcfaf6307b5 2002-10-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
262 {
4bcfaf6307b5 2002-10-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
263 if (request->cancel)
4bcfaf6307b5 2002-10-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
264 break;
4bcfaf6307b5 2002-10-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
265 else
4bcfaf6307b5 2002-10-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
266 continue;
4bcfaf6307b5 2002-10-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
267 }
4bcfaf6307b5 2002-10-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
268 else if (ret <= 0)
4bcfaf6307b5 2002-10-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
269 {
4bcfaf6307b5 2002-10-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
270 request->logging_function (gftp_logging_error, request->user_data,
4bcfaf6307b5 2002-10-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
271 _("Connection to %s timed out\n"),
4bcfaf6307b5 2002-10-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
272 request->hostname);
4bcfaf6307b5 2002-10-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
273 gftp_disconnect (request);
4bcfaf6307b5 2002-10-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
274 return (-1);
4bcfaf6307b5 2002-10-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
275 }
4bcfaf6307b5 2002-10-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
276
4bcfaf6307b5 2002-10-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
277 if ((len = read (fileno (request->datafd), buf, size)) == -1)
4bcfaf6307b5 2002-10-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
278 {
4bcfaf6307b5 2002-10-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
279 if (errno == EINTR)
4bcfaf6307b5 2002-10-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
280 {
4bcfaf6307b5 2002-10-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
281 if (request->cancel)
4bcfaf6307b5 2002-10-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
282 break;
4bcfaf6307b5 2002-10-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
283 else
4bcfaf6307b5 2002-10-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
284 continue;
4bcfaf6307b5 2002-10-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
285 }
4bcfaf6307b5 2002-10-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
286
4bcfaf6307b5 2002-10-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
287 request->logging_function (gftp_logging_error, request->user_data,
4bcfaf6307b5 2002-10-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
288 _("Error reading from host %s: %s\n"),
4bcfaf6307b5 2002-10-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
289 request->hostname,
4bcfaf6307b5 2002-10-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
290 g_strerror (errno));
4bcfaf6307b5 2002-10-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
291 gftp_disconnect (request);
4bcfaf6307b5 2002-10-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
292 return (-1);
4bcfaf6307b5 2002-10-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
293 }
4bcfaf6307b5 2002-10-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
294 }
4bcfaf6307b5 2002-10-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
295 while (errno == EINTR && !request->cancel);
4bcfaf6307b5 2002-10-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
296
4bcfaf6307b5 2002-10-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
297 if (errno == EINTR && request->cancel)
4bcfaf6307b5 2002-10-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
298 {
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
299 gftp_disconnect (request);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
300 return (-1);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
301 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
302
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
303 return (len);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
304 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
305
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
306
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
307 size_t
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
308 gftp_put_next_file_chunk (gftp_request * request, char *buf, size_t size)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
309 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
310 struct timeval tv;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
311 size_t len, ret;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
312 fd_set fset;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
313 char *pos;
41
4bcfaf6307b5 2002-10-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
314 int sret;
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
315
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
316 g_return_val_if_fail (request != NULL, -2);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
317
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
318 ret = size;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
319 if (request->put_next_file_chunk != NULL)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
320 return (request->put_next_file_chunk (request, buf, size));
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
321
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
322 if (size == 0)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
323 return (0);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
324
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
325 pos = buf;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
326 while (size > 0)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
327 {
41
4bcfaf6307b5 2002-10-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
328 errno = 0;
4bcfaf6307b5 2002-10-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
329 do
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
330 {
41
4bcfaf6307b5 2002-10-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
331 FD_ZERO (&fset);
4bcfaf6307b5 2002-10-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
332 FD_SET (fileno (request->datafd), &fset);
4bcfaf6307b5 2002-10-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
333 tv.tv_sec = request->network_timeout;
4bcfaf6307b5 2002-10-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
334 tv.tv_usec = 0;
4bcfaf6307b5 2002-10-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
335 sret = select (fileno (request->datafd) + 1, NULL, &fset, NULL, &tv);
4bcfaf6307b5 2002-10-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
336 if (sret == -1 && errno == EINTR)
4bcfaf6307b5 2002-10-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
337 {
4bcfaf6307b5 2002-10-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
338 if (request->cancel)
4bcfaf6307b5 2002-10-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
339 break;
4bcfaf6307b5 2002-10-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
340 else
4bcfaf6307b5 2002-10-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
341 continue;
4bcfaf6307b5 2002-10-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
342 }
4bcfaf6307b5 2002-10-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
343 else if (sret <= 0)
4bcfaf6307b5 2002-10-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
344 {
4bcfaf6307b5 2002-10-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
345 request->logging_function (gftp_logging_error, request->user_data,
4bcfaf6307b5 2002-10-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
346 _("Connection to %s timed out\n"),
4bcfaf6307b5 2002-10-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
347 request->hostname);
4bcfaf6307b5 2002-10-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
348 gftp_disconnect (request);
4bcfaf6307b5 2002-10-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
349 return (-1);
4bcfaf6307b5 2002-10-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
350 }
4bcfaf6307b5 2002-10-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
351
4bcfaf6307b5 2002-10-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
352 if ((len = write (fileno (request->datafd), pos, size)) < 0)
4bcfaf6307b5 2002-10-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
353 {
4bcfaf6307b5 2002-10-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
354 if (sret == -1 && errno == EINTR)
4bcfaf6307b5 2002-10-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
355 {
4bcfaf6307b5 2002-10-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
356 if (request->cancel)
4bcfaf6307b5 2002-10-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
357 break;
4bcfaf6307b5 2002-10-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
358 else
4bcfaf6307b5 2002-10-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
359 continue;
4bcfaf6307b5 2002-10-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
360 }
4bcfaf6307b5 2002-10-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
361
4bcfaf6307b5 2002-10-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
362 request->logging_function (gftp_logging_error, request->user_data,
4bcfaf6307b5 2002-10-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
363 _("Error writing to host %s: %s\n"),
4bcfaf6307b5 2002-10-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
364 request->hostname,
4bcfaf6307b5 2002-10-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
365 g_strerror (errno));
4bcfaf6307b5 2002-10-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
366 gftp_disconnect (request);
4bcfaf6307b5 2002-10-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
367 return (-1);
4bcfaf6307b5 2002-10-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
368 }
4bcfaf6307b5 2002-10-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
369 size -= len;
4bcfaf6307b5 2002-10-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
370 pos += len;
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
371 }
41
4bcfaf6307b5 2002-10-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
372 while (errno == EINTR && !request->cancel);
4bcfaf6307b5 2002-10-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
373 }
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
374
41
4bcfaf6307b5 2002-10-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
375 if (errno == EINTR && request->cancel)
4bcfaf6307b5 2002-10-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
376 {
4bcfaf6307b5 2002-10-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
377 gftp_disconnect (request);
4bcfaf6307b5 2002-10-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
378 return (-1);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
379 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
380
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
381 return (ret);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
382 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
383
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
384
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
385 int
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
386 gftp_end_transfer (gftp_request * request)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
387 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
388 int ret;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
389
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
390 g_return_val_if_fail (request != NULL, -2);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
391
40
66c064fd05bc 2002-10-17 Brian Masney <masneyb@gftp.org>
masneyb
parents: 39
diff changeset
392 if (!request->cached &&
66c064fd05bc 2002-10-17 Brian Masney <masneyb@gftp.org>
masneyb
parents: 39
diff changeset
393 request->end_transfer != NULL)
66c064fd05bc 2002-10-17 Brian Masney <masneyb@gftp.org>
masneyb
parents: 39
diff changeset
394 ret = request->end_transfer (request);
66c064fd05bc 2002-10-17 Brian Masney <masneyb@gftp.org>
masneyb
parents: 39
diff changeset
395 else
66c064fd05bc 2002-10-17 Brian Masney <masneyb@gftp.org>
masneyb
parents: 39
diff changeset
396 ret = 0;
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
397
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
398 if (request->cachefd != NULL)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
399 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
400 fclose (request->cachefd);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
401 request->cachefd = NULL;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
402 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
403
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
404 if (request->last_dir_entry)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
405 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
406 g_free (request->last_dir_entry);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
407 request->last_dir_entry = NULL;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
408 request->last_dir_entry_len = 0;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
409 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
410
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
411 return (ret);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
412 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
413
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
414
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
415 int
40
66c064fd05bc 2002-10-17 Brian Masney <masneyb@gftp.org>
masneyb
parents: 39
diff changeset
416 gftp_abort_transfer (gftp_request * request)
66c064fd05bc 2002-10-17 Brian Masney <masneyb@gftp.org>
masneyb
parents: 39
diff changeset
417 {
66c064fd05bc 2002-10-17 Brian Masney <masneyb@gftp.org>
masneyb
parents: 39
diff changeset
418 g_return_val_if_fail (request != NULL, -2);
66c064fd05bc 2002-10-17 Brian Masney <masneyb@gftp.org>
masneyb
parents: 39
diff changeset
419
66c064fd05bc 2002-10-17 Brian Masney <masneyb@gftp.org>
masneyb
parents: 39
diff changeset
420 if (request->abort_transfer == NULL)
66c064fd05bc 2002-10-17 Brian Masney <masneyb@gftp.org>
masneyb
parents: 39
diff changeset
421 return (-2);
66c064fd05bc 2002-10-17 Brian Masney <masneyb@gftp.org>
masneyb
parents: 39
diff changeset
422
66c064fd05bc 2002-10-17 Brian Masney <masneyb@gftp.org>
masneyb
parents: 39
diff changeset
423 return (request->abort_transfer (request));
66c064fd05bc 2002-10-17 Brian Masney <masneyb@gftp.org>
masneyb
parents: 39
diff changeset
424 }
66c064fd05bc 2002-10-17 Brian Masney <masneyb@gftp.org>
masneyb
parents: 39
diff changeset
425
66c064fd05bc 2002-10-17 Brian Masney <masneyb@gftp.org>
masneyb
parents: 39
diff changeset
426
66c064fd05bc 2002-10-17 Brian Masney <masneyb@gftp.org>
masneyb
parents: 39
diff changeset
427 int
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
428 gftp_list_files (gftp_request * request)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
429 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
430 FILE * fd;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
431
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
432 g_return_val_if_fail (request != NULL, -2);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
433
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
434 request->cached = 0;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
435 if (request->use_cache && (fd = gftp_find_cache_entry (request)) != NULL)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
436 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
437 request->logging_function (gftp_logging_misc, request->user_data,
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
438 _("Loading directory listing %s from cache\n"),
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
439 request->directory);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
440
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
441 request->cachefd = fd;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
442 request->cached = 1;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
443 return (0);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
444 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
445 else if (request->use_cache)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
446 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
447 request->cachefd = gftp_new_cache_entry (request);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
448 request->cached = 0;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
449 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
450
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
451 if (request->list_files == NULL)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
452 return (-2);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
453 return (request->list_files (request));
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
454 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
455
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
456
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
457 int
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
458 gftp_get_next_file (gftp_request * request, char *filespec, gftp_file * fle)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
459 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
460 FILE * fd;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
461 int ret;
45
311e29c40ed6 2002-10-31 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
462 #if GLIB_MAJOR_VERSION > 1
311e29c40ed6 2002-10-31 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
463 gsize bread, bwrite;
311e29c40ed6 2002-10-31 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
464 char *tempstr;
46
3da7765bc439 2002-10-31 Brian Masney <masneyb@gftp.org>
masneyb
parents: 45
diff changeset
465 GError * error;
45
311e29c40ed6 2002-10-31 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
466 #endif
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
467
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
468 g_return_val_if_fail (request != NULL, -2);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
469
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
470 if (request->get_next_file == NULL)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
471 return (-2);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
472
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
473 if (request->cached && request->cachefd != NULL)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
474 fd = request->cachefd;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
475 else
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
476 fd = request->datafd;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
477
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
478 memset (fle, 0, sizeof (*fle));
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
479 do
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
480 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
481 gftp_file_destroy (fle);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
482 ret = request->get_next_file (request, fle, fd);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
483
45
311e29c40ed6 2002-10-31 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
484 #if GLIB_MAJOR_VERSION > 1
311e29c40ed6 2002-10-31 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
485 if (fle->file != NULL && !g_utf8_validate (fle->file, -1, NULL))
311e29c40ed6 2002-10-31 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
486 {
46
3da7765bc439 2002-10-31 Brian Masney <masneyb@gftp.org>
masneyb
parents: 45
diff changeset
487 error = NULL;
45
311e29c40ed6 2002-10-31 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
488 if ((tempstr = g_locale_to_utf8 (fle->file, -1, &bread,
46
3da7765bc439 2002-10-31 Brian Masney <masneyb@gftp.org>
masneyb
parents: 45
diff changeset
489 &bwrite, &error)) != NULL)
45
311e29c40ed6 2002-10-31 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
490 {
311e29c40ed6 2002-10-31 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
491 g_free (fle->file);
311e29c40ed6 2002-10-31 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
492 fle->file = tempstr;
311e29c40ed6 2002-10-31 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
493 }
46
3da7765bc439 2002-10-31 Brian Masney <masneyb@gftp.org>
masneyb
parents: 45
diff changeset
494 else
3da7765bc439 2002-10-31 Brian Masney <masneyb@gftp.org>
masneyb
parents: 45
diff changeset
495 g_warning ("Error when converting %s to UTF-8: %s\n", fle->file,
3da7765bc439 2002-10-31 Brian Masney <masneyb@gftp.org>
masneyb
parents: 45
diff changeset
496 error->message);
45
311e29c40ed6 2002-10-31 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
497 }
311e29c40ed6 2002-10-31 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
498 #endif
311e29c40ed6 2002-10-31 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
499
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
500 if (ret >= 0 && !request->cached && request->cachefd != NULL &&
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
501 request->last_dir_entry != NULL)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
502 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
503 fwrite (request->last_dir_entry, 1, request->last_dir_entry_len,
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
504 request->cachefd);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
505 if (ferror (request->cachefd))
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
506 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
507 request->logging_function (gftp_logging_error, request->user_data,
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
508 _("Error: Cannot write to cache: %s\n"),
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
509 g_strerror (errno));
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
510 fclose (request->cachefd);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
511 request->cachefd = NULL;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
512 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
513 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
514 } while (ret > 0 && !gftp_match_filespec (fle->file, filespec));
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
515
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
516 return (ret);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
517 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
518
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
519
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
520 int
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
521 gftp_parse_url (gftp_request * request, const char *url)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
522 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
523 char *pos, *endpos, *endhostpos, *str, tempchar;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
524 const char *stpos;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
525 int len, i;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
526
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
527 g_return_val_if_fail (request != NULL, -2);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
528 g_return_val_if_fail (url != NULL, -2);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
529
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
530 for (stpos = url; *stpos == ' '; stpos++);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
531
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
532 if ((pos = strstr (stpos, "://")) != NULL)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
533 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
534 *pos = '\0';
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
535
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
536 for (i = 0; gftp_protocols[i].url_prefix; i++)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
537 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
538 if (strcmp (gftp_protocols[i].url_prefix, stpos) == 0)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
539 break;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
540 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
541
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
542 if (gftp_protocols[i].url_prefix == NULL)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
543 return (-2);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
544 *pos = ':';
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
545 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
546 else
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
547 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
548 for (i = 0; gftp_protocols[i].url_prefix; i++)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
549 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
550 if (strcmp (gftp_protocols[i].name, default_protocol) == 0)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
551 break;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
552 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
553
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
554 if (gftp_protocols[i].url_prefix == NULL)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
555 i = GFTP_FTP_NUM;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
556 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
557
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
558 gftp_protocols[i].init (request);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
559
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
560 if (request->parse_url != NULL)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
561 return (request->parse_url (request, url));
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
562
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
563 if (i == GFTP_LOCAL_NUM)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
564 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
565 request->directory = g_malloc (strlen (stpos + 6) + 1);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
566 strcpy (request->directory, stpos + 6);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
567 return (0);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
568 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
569
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
570 for (; *stpos == ' '; stpos++);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
571 str = g_malloc (strlen (stpos) + 1);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
572 strcpy (str, stpos);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
573 for (pos = str + strlen (str) - 1; *pos == ' '; pos--)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
574 *pos = '\0';
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
575
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
576 pos = str;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
577 len = strlen (request->url_prefix);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
578 if (strncmp (pos, request->url_prefix, len) == 0
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
579 && strncmp (pos + len, "://", 3) == 0)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
580 pos += len + 3;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
581
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
582 if ((endhostpos = strchr (pos, '@')) != NULL)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
583 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
584 /* A user/password was entered */
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
585 if ((endpos = strchr (pos, ':')) == NULL || endhostpos < endpos)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
586 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
587 /* No password was entered */
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
588 gftp_set_password (request, "");
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
589 endpos = endhostpos;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
590 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
591
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
592 *endpos = '\0';
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
593 gftp_set_username (request, pos);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
594
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
595 pos = endpos + 1;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
596 if ((endpos = strchr (pos, '@')) != NULL)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
597 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
598 if (strchr (endpos + 1, '@') != NULL)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
599 endpos = strchr (endpos + 1, '@');
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
600 *endpos = '\0';
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
601 gftp_set_password (request, pos);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
602
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
603 pos = endpos + 1;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
604 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
605 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
606
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
607 /* Now get the hostname and an optional port and optional directory */
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
608 endhostpos = pos + strlen (pos);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
609 if ((endpos = strchr (pos, ':')) != NULL)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
610 endhostpos = endpos;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
611 else if ((endpos = strchr (pos, '/')) != NULL)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
612 endhostpos = endpos;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
613 tempchar = *endhostpos;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
614 *endhostpos = '\0';
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
615 gftp_set_hostname (request, pos);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
616 *endhostpos = tempchar;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
617
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
618 if ((endpos = strchr (pos, ':')) != NULL)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
619 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
620 /* A port was entered */
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
621 pos = endpos + 1;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
622 gftp_set_port (request, strtol (pos, NULL, 10));
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
623 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
624 if ((endpos = strchr (pos, '/')) != NULL)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
625 gftp_set_directory (request, endpos);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
626 g_free (str);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
627 return (0);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
628 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
629
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
630
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
631 int
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
632 gftp_set_data_type (gftp_request * request, int data_type)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
633 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
634 g_return_val_if_fail (request != NULL, -2);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
635
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
636 if (request->set_data_type == NULL)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
637 return (-2);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
638 return (request->set_data_type (request, data_type));
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
639 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
640
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
641
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
642 void
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
643 gftp_set_hostname (gftp_request * request, const char *hostname)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
644 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
645 g_return_if_fail (request != NULL);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
646 g_return_if_fail (hostname != NULL);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
647
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
648 if (request->hostname)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
649 g_free (request->hostname);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
650 request->hostname = g_malloc (strlen (hostname) + 1);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
651 strcpy (request->hostname, hostname);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
652 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
653
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
654
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
655 void
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
656 gftp_set_username (gftp_request * request, const char *username)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
657 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
658 g_return_if_fail (request != NULL);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
659 g_return_if_fail (username != NULL);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
660
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
661 if (request->username)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
662 g_free (request->username);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
663 request->username = g_malloc (strlen (username) + 1);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
664 strcpy (request->username, username);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
665 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
666
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
667
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
668 void
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
669 gftp_set_password (gftp_request * request, const char *password)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
670 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
671 g_return_if_fail (request != NULL);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
672 g_return_if_fail (password != NULL);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
673
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
674 if (request->password)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
675 g_free (request->password);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
676 request->password = g_malloc (strlen (password) + 1);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
677 strcpy (request->password, password);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
678 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
679
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
680
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
681 void
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
682 gftp_set_account (gftp_request * request, const char *account)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
683 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
684 g_return_if_fail (request != NULL);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
685 g_return_if_fail (account != NULL);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
686
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
687 if (request->account)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
688 g_free (request->account);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
689 request->account = g_malloc (strlen (account) + 1);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
690 strcpy (request->account, account);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
691 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
692
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
693
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
694 int
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
695 gftp_set_directory (gftp_request * request, const char *directory)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
696 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
697 g_return_val_if_fail (request != NULL, -2);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
698 g_return_val_if_fail (directory != NULL, -2);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
699
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
700
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
701 if (request->sockfd == NULL)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
702 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
703 if (directory != request->directory)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
704 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
705 if (request->directory)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
706 g_free (request->directory);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
707 request->directory = g_malloc (strlen (directory) + 1);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
708 strcpy (request->directory, directory);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
709 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
710 return (0);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
711 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
712 else if (request->chdir == NULL)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
713 return (-2);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
714 return (request->chdir (request, directory));
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
715 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
716
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
717
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
718 void
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
719 gftp_set_port (gftp_request * request, unsigned int port)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
720 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
721 g_return_if_fail (request != NULL);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
722
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
723 request->port = port;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
724 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
725
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
726
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
727 void
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
728 gftp_set_proxy_hostname (gftp_request * request, const char *hostname)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
729 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
730 g_return_if_fail (request != NULL);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
731 g_return_if_fail (hostname != NULL);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
732
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
733 if (request->proxy_hostname)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
734 g_free (request->proxy_hostname);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
735 request->proxy_hostname = g_malloc (strlen (hostname) + 1);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
736 strcpy (request->proxy_hostname, hostname);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
737 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
738
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
739
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
740 void
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
741 gftp_set_proxy_username (gftp_request * request, const char *username)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
742 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
743 g_return_if_fail (request != NULL);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
744 g_return_if_fail (username != NULL);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
745
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
746 if (request->proxy_username)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
747 g_free (request->proxy_username);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
748 request->proxy_username = g_malloc (strlen (username) + 1);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
749 strcpy (request->proxy_username, username);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
750 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
751
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
752
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
753 void
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
754 gftp_set_proxy_password (gftp_request * request, const char *password)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
755 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
756 g_return_if_fail (request != NULL);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
757 g_return_if_fail (password != NULL);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
758
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
759 if (request->proxy_password)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
760 g_free (request->proxy_password);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
761 request->proxy_password = g_malloc (strlen (password) + 1);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
762 strcpy (request->proxy_password, password);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
763 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
764
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
765
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
766 void
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
767 gftp_set_proxy_account (gftp_request * request, const char *account)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
768 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
769 g_return_if_fail (request != NULL);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
770 g_return_if_fail (account != NULL);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
771
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
772 if (request->proxy_account)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
773 g_free (request->proxy_account);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
774 request->proxy_account = g_malloc (strlen (account) + 1);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
775 strcpy (request->proxy_account, account);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
776 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
777
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
778
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
779 void
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
780 gftp_set_proxy_port (gftp_request * request, unsigned int port)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
781 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
782 g_return_if_fail (request != NULL);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
783
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
784 request->proxy_port = port;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
785 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
786
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
787
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
788 int
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
789 gftp_remove_directory (gftp_request * request, const char *directory)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
790 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
791 g_return_val_if_fail (request != NULL, -2);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
792
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
793 if (request->rmdir == NULL)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
794 return (-2);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
795 return (request->rmdir (request, directory));
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
796 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
797
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
798
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
799 int
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
800 gftp_remove_file (gftp_request * request, const char *file)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
801 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
802 g_return_val_if_fail (request != NULL, -2);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
803
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
804 if (request->rmfile == NULL)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
805 return (-2);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
806 return (request->rmfile (request, file));
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
807 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
808
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
809
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
810 int
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
811 gftp_make_directory (gftp_request * request, const char *directory)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
812 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
813 g_return_val_if_fail (request != NULL, -2);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
814
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
815 if (request->mkdir == NULL)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
816 return (-2);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
817 return (request->mkdir (request, directory));
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
818 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
819
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
820
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
821 int
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
822 gftp_rename_file (gftp_request * request, const char *oldname,
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
823 const char *newname)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
824 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
825 g_return_val_if_fail (request != NULL, -2);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
826
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
827 if (request->rename == NULL)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
828 return (-2);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
829 return (request->rename (request, oldname, newname));
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
830 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
831
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
832
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
833 int
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
834 gftp_chmod (gftp_request * request, const char *file, int mode)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
835 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
836 g_return_val_if_fail (request != NULL, -2);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
837
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
838 if (request->chmod == NULL)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
839 return (-2);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
840 return (request->chmod (request, file, mode));
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
841 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
842
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
843
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
844 int
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
845 gftp_set_file_time (gftp_request * request, const char *file, time_t datetime)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
846 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
847 g_return_val_if_fail (request != NULL, -2);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
848
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
849 if (request->set_file_time == NULL)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
850 return (-2);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
851 return (request->set_file_time (request, file, datetime));
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
852 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
853
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
854
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
855 char
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
856 gftp_site_cmd (gftp_request * request, const char *command)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
857 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
858 g_return_val_if_fail (request != NULL, -2);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
859
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
860 if (request->site == NULL)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
861 return (-2);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
862 return (request->site (request, command));
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
863 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
864
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
865
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
866 void
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
867 gftp_set_proxy_config (gftp_request * request, const char *proxy_config)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
868 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
869 int len;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
870
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
871 g_return_if_fail (request != NULL);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
872 g_return_if_fail (proxy_config != NULL);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
873
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
874 if (request->proxy_config != NULL)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
875 g_free (request->proxy_config);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
876
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
877 len = strlen (proxy_config);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
878
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
879 if (len > 0 && (proxy_config[len - 1] != 'n' ||
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
880 proxy_config[len - 2] != '%'))
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
881 len += 2;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
882
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
883 request->proxy_config = g_malloc (len + 1);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
884 strcpy (request->proxy_config, proxy_config);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
885 if (len != strlen (proxy_config))
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
886 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
887 request->proxy_config[len - 2] = '%';
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
888 request->proxy_config[len - 1] = 'n';
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
889 request->proxy_config[len] = '\0';
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
890 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
891 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
892
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
893
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
894 long
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
895 gftp_get_file_size (gftp_request * request, const char *filename)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
896 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
897 g_return_val_if_fail (request != NULL, 0);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
898
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
899 if (request->get_file_size == NULL)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
900 return (0);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
901 return (request->get_file_size (request, filename));
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
902 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
903
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
904
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
905 int
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
906 gftp_need_proxy (gftp_request * request, char *service)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
907 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
908 gftp_proxy_hosts * hostname;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
909 unsigned char addy[4];
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
910 struct sockaddr *addr;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
911 GList * templist;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
912 gint32 netaddr;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
913 char *pos;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
914 #if defined (HAVE_GETADDRINFO) && defined (HAVE_GAI_STRERROR)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
915 struct addrinfo hints;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
916 int port, errnum;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
917 char serv[8];
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
918
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
919 request->hostp = NULL;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
920 if (proxy_hosts == NULL)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
921 return (request->proxy_hostname != NULL
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
922 && *request->proxy_hostname != '\0'
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
923 && request->proxy_config != NULL
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
924 && *request->proxy_config != '\0');
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
925
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
926 memset (&hints, 0, sizeof (hints));
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
927 hints.ai_flags = AI_CANONNAME;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
928 hints.ai_family = AF_INET;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
929 hints.ai_socktype = SOCK_STREAM;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
930
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
931 port = request->use_proxy ? request->proxy_port : request->port;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
932 if (port == 0)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
933 strcpy (serv, service);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
934 else
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
935 snprintf (serv, sizeof (serv), "%d", port);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
936
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
937 request->logging_function (gftp_logging_misc, request->user_data,
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
938 _("Looking up %s\n"), request->hostname);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
939
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
940 if ((errnum = getaddrinfo (request->hostname, serv, &hints,
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
941 &request->hostp)) != 0)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
942 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
943 request->logging_function (gftp_logging_error, request->user_data,
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
944 _("Cannot look up hostname %s: %s\n"),
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
945 request->hostname, gai_strerror (errnum));
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
946 return (-1);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
947 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
948
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
949 addr = request->hostp->ai_addr;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
950
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
951 #else /* !HAVE_GETADDRINFO */
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
952
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
953 request->hostp = NULL;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
954 if (proxy_hosts == NULL)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
955 return (request->proxy_hostname != NULL
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
956 && *request->proxy_hostname != '\0'
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
957 && request->proxy_config != NULL
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
958 && *request->proxy_config != '\0');
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
959
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
960 request->logging_function (gftp_logging_misc, request->user_data,
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
961 _("Looking up %s\n"), request->hostname);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
962
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
963 if (!(request->hostp = r_gethostbyname (request->hostname, &request->host,
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
964 NULL)))
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
965 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
966 request->logging_function (gftp_logging_error, request->user_data,
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
967 _("Cannot look up hostname %s: %s\n"),
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
968 request->hostname, g_strerror (errno));
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
969 return (-1);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
970 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
971
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
972 addr = (struct sockaddr *) request->host.h_addr_list[0];
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
973
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
974 #endif /* HAVE_GETADDRINFO */
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
975
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
976 templist = proxy_hosts;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
977 while (templist != NULL)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
978 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
979 hostname = templist->data;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
980 if (hostname->domain &&
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
981 strlen (request->hostname) > strlen (hostname->domain))
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
982 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
983 pos = request->hostname + strlen (request->hostname) -
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
984 strlen (hostname->domain);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
985 if (strcmp (hostname->domain, pos) == 0)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
986 return (0);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
987 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
988
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
989 if (hostname->ipv4_network_address != 0)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
990 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
991 memcpy (addy, addr, sizeof (addy));
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
992 netaddr =
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
993 (((addy[0] & 0xff) << 24) | ((addy[1] & 0xff) << 16) |
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
994 ((addy[2] & 0xff) << 8) | (addy[3] & 0xff)) &
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
995 hostname->ipv4_netmask;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
996 if (netaddr == hostname->ipv4_network_address)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
997 return (0);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
998 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
999 templist = templist->next;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1000 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1001 return (request->proxy_hostname != NULL && *request->proxy_hostname != '\0'
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1002 && request->proxy_config != NULL && *request->proxy_config != '\0');
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1003 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1004
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1005
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1006 char *
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1007 gftp_convert_ascii (char *buf, ssize_t *len, int direction)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1008 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1009 ssize_t i, j, newsize;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1010 char *tempstr;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1011
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1012 if (direction == GFTP_DIRECTION_DOWNLOAD)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1013 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1014 for (i = 0, j = 0; i < *len; i++)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1015 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1016 if (buf[i] != '\r')
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1017 buf[j++] = buf[i];
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1018 else
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1019 --*len;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1020 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1021 tempstr = buf;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1022 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1023 else
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1024 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1025 newsize = 0;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1026 for (i = 0; i < *len; i++)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1027 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1028 newsize++;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1029 if (i > 0 && buf[i] == '\n' && buf[i - 1] != '\r')
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1030 newsize++;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1031 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1032 tempstr = g_malloc (newsize);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1033
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1034 for (i = 0, j = 0; i < *len; i++)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1035 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1036 if (i > 0 && buf[i] == '\n' && buf[i - 1] != '\r')
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1037 tempstr[j++] = '\r';
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1038 tempstr[j++] = buf[i];
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1039 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1040 *len = newsize;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1041 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1042 return (tempstr);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1043 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1044
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1045
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1046 int
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1047 gftp_parse_ls (const char *lsoutput, gftp_file * fle)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1048 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1049 int result, cols;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1050 char *str, *pos;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1051
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1052 g_return_val_if_fail (lsoutput != NULL, -2);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1053 g_return_val_if_fail (fle != NULL, -2);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1054
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1055 str = g_malloc (strlen (lsoutput) + 1);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1056 strcpy (str, lsoutput);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1057 memset (fle, 0, sizeof (*fle));
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1058
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1059 if (str[strlen (str) - 1] == '\n')
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1060 str[strlen (str) - 1] = '\0';
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1061 if (str[strlen (str) - 1] == '\r')
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1062 str[strlen (str) - 1] = '\0';
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1063 if (*lsoutput == '+') /* EPLF format */
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1064 result = gftp_parse_ls_eplf (str, fle);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1065 else if (isdigit ((int) str[0]) && str[2] == '-') /* DOS/WinNT format */
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1066 result = gftp_parse_ls_nt (str, fle);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1067 else if (str[1] == ' ' && str[2] == '[') /* Novell format */
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1068 result = gftp_parse_ls_novell (str, fle);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1069 else
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1070 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1071 /* UNIX/MacOS format */
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1072
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1073 /* If there is no space between the attribs and links field, just make one */
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1074 if (strlen (str) > 10)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1075 str[10] = ' ';
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1076
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1077 /* Determine the number of columns */
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1078 cols = 0;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1079 pos = str;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1080 while (*pos != '\0')
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1081 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1082 while (*pos != '\0' && *pos != ' ' && *pos != '\t')
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1083 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1084 if (*pos == ':')
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1085 break;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1086 pos++;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1087 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1088
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1089 cols++;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1090
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1091 if (*pos == ':')
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1092 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1093 cols++;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1094 break;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1095 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1096
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1097 while (*pos == ' ' || *pos == '\t')
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1098 pos++;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1099 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1100
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1101 if (cols > 6)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1102 result = gftp_parse_ls_unix (str, cols, fle);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1103 else
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1104 result = -2;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1105 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1106 g_free (str);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1107
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1108 if (fle->attribs == NULL)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1109 return (result);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1110
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1111 if (*fle->attribs == 'd')
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1112 fle->isdir = 1;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1113 if (*fle->attribs == 'l')
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1114 fle->islink = 1;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1115 if (strchr (fle->attribs, 'x') != NULL && !fle->isdir && !fle->islink)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1116 fle->isexe = 1;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1117 if (*fle->attribs == 'b')
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1118 fle->isblock = 1;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1119 if (*fle->attribs == 'c')
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1120 fle->ischar = 1;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1121 if (*fle->attribs == 's')
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1122 fle->issocket = 1;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1123 if (*fle->attribs == 'p')
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1124 fle->isfifo = 1;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1125
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1126 return (result);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1127 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1128
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1129
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1130 static time_t
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1131 parse_time (char **str)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1132 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1133 const char *months[] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul",
14
83090328581e * More largefile support. Hopefully all that is left is the configure stuff
masneyb
parents: 7
diff changeset
1134 "Aug", "Sep", "Oct", "Nov", "Dec" };
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1135 char *startpos, *endpos, *datepos;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1136 struct tm curtime, tt;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1137 time_t t;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1138 int i;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1139
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1140 startpos = *str;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1141 memset (&tt, 0, sizeof (tt));
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1142 tt.tm_isdst = -1;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1143 if (isdigit ((int) startpos[0]) && startpos[2] == '-')
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1144 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1145 /* This is how DOS will return the date/time */
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1146 /* 07-06-99 12:57PM */
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1147 if ((endpos = strchr (startpos, '-')) == NULL)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1148 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1149 g_free (str);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1150 return (0);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1151 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1152 tt.tm_mon = strtol (startpos, NULL, 10) - 1;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1153
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1154 startpos = endpos + 1;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1155 if ((endpos = strchr (startpos, '-')) == NULL)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1156 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1157 g_free (str);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1158 return (0);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1159 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1160 tt.tm_mday = strtol (startpos, NULL, 10);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1161
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1162 startpos = endpos + 1;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1163 if ((endpos = strchr (startpos, ' ')) == NULL)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1164 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1165 g_free (str);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1166 return (0);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1167 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1168 tt.tm_year = strtol (startpos, NULL, 10);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1169
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1170 while (*endpos == ' ')
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1171 endpos++;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1172
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1173 startpos = endpos + 1;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1174 if ((endpos = strchr (startpos, ':')) == NULL)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1175 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1176 g_free (str);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1177 return (0);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1178 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1179 tt.tm_hour = strtol (startpos, NULL, 10);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1180
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1181 startpos = endpos + 1;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1182 while ((*endpos != 'A') && (*endpos != 'P'))
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1183 endpos++;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1184 if (*endpos == 'P')
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1185 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1186 if (tt.tm_hour == 12)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1187 tt.tm_hour = 0;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1188 else
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1189 tt.tm_hour += 12;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1190 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1191 tt.tm_min = strtol (startpos, NULL, 10);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1192 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1193 else
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1194 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1195 /* This is how most UNIX, Novell, and MacOS ftp servers send their time */
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1196 /* Jul 06 12:57 */
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1197 t = time (NULL);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1198 curtime = *localtime (&t);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1199
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1200 /* Get the month */
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1201 if ((endpos = strchr (startpos, ' ')) == NULL)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1202 return (0);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1203 for (i = 0; i < 12; i++)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1204 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1205 if (strncmp (months[i], startpos, 3) == 0)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1206 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1207 tt.tm_mon = i;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1208 break;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1209 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1210 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1211
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1212 /* Skip the blanks till we get to the next entry */
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1213 startpos = endpos + 1;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1214 while (*startpos == ' ')
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1215 startpos++;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1216
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1217 /* Get the day */
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1218 if ((endpos = strchr (startpos, ' ')) == NULL)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1219 return (0);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1220 tt.tm_mday = strtol (startpos, NULL, 10);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1221
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1222 /* Skip the blanks till we get to the next entry */
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1223 startpos = endpos + 1;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1224 while (*startpos == ' ')
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1225 startpos++;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1226
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1227 if ((datepos = strchr (startpos, ':')) != NULL)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1228 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1229 /* No year was specified. We will use the current year */
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1230 tt.tm_year = curtime.tm_year;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1231
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1232 /* If the date is in the future, than the year is from last year */
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1233 if ((tt.tm_mon > curtime.tm_mon) ||
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1234 ((tt.tm_mon == curtime.tm_mon) && tt.tm_mday > curtime.tm_mday))
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1235 tt.tm_year--;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1236
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1237 /* Get the hours and the minutes */
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1238 tt.tm_hour = strtol (startpos, NULL, 10);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1239 tt.tm_min = strtol (datepos + 1, NULL, 10);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1240 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1241 else
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1242 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1243 /* Get the year. The hours and minutes will be assumed to be 0 */
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1244 tt.tm_year = strtol (startpos, NULL, 10) - 1900;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1245 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1246 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1247 *str = startpos;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1248 return (mktime (&tt));
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1249 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1250
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1251
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1252 static int
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1253 gftp_parse_ls_eplf (char *str, gftp_file * fle)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1254 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1255 char *startpos;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1256
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1257 startpos = str;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1258 fle->attribs = g_malloc (11);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1259 strcpy (fle->attribs, "----------");
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1260 while (startpos)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1261 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1262 startpos++;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1263 switch (*startpos)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1264 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1265 case '/':
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1266 *fle->attribs = 'd';
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1267 break;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1268 case 's':
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1269 fle->size = strtol (startpos + 1, NULL, 10);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1270 break;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1271 case 'm':
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1272 fle->datetime = strtol (startpos + 1, NULL, 10);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1273 break;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1274 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1275 startpos = strchr (startpos, ',');
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1276 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1277 if ((startpos = strchr (str, 9)) == NULL)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1278 return (-2);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1279 fle->file = g_malloc (strlen (startpos));
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1280 strcpy (fle->file, startpos + 1);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1281 fle->user = g_malloc (8);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1282 strcpy (fle->user, _("unknown"));
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1283 fle->group = g_malloc (8);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1284 strcpy (fle->group, _("unknown"));
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1285 return (0);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1286 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1287
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1288
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1289 static int
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1290 gftp_parse_ls_unix (char *str, int cols, gftp_file * fle)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1291 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1292 char *endpos, *startpos;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1293
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1294 startpos = str;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1295 /* Copy file attributes */
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1296 if ((startpos = copy_token (&fle->attribs, startpos)) == NULL)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1297 return (-2);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1298
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1299 if (cols >= 9)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1300 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1301 /* Skip the number of links */
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1302 startpos = goto_next_token (startpos);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1303
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1304 /* Copy the user that owns this file */
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1305 if ((startpos = copy_token (&fle->user, startpos)) == NULL)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1306 return (-2);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1307
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1308 /* Copy the group that owns this file */
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1309 if ((startpos = copy_token (&fle->group, startpos)) == NULL)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1310 return (-2);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1311 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1312 else
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1313 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1314 fle->group = g_malloc (8);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1315 strcpy (fle->group, _("unknown"));
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1316 if (cols == 8)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1317 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1318 if ((startpos = copy_token (&fle->user, startpos)) == NULL)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1319 return (-2);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1320 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1321 else
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1322 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1323 fle->user = g_malloc (8);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1324 strcpy (fle->user, _("unknown"));
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1325 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1326 startpos = goto_next_token (startpos);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1327 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1328
39
474d562c7268 2002-10-15 Brian Masney <masneyb@gftp.org>
masneyb
parents: 33
diff changeset
1329 /* FIXME - this is a bug if there is some extra spaces in the file */
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1330 /* See if this is a Cray directory listing. It has the following format:
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1331 drwx------ 2 feiliu g913 DK common 4096 Sep 24 2001 wv */
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1332 if (cols == 11 && strstr (str, "->") == NULL)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1333 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1334 startpos = goto_next_token (startpos);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1335 startpos = goto_next_token (startpos);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1336 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1337
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1338 /* See if this is a block or character device. We will store the major number
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1339 in the high word and the minor number in the low word. */
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1340 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
1341 fle->attribs[0] == 'c') &&
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1342 ((endpos = strchr (startpos, ',')) != NULL))
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1343 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1344 fle->size = strtol (startpos, NULL, 10) << 16;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1345
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1346 startpos = endpos + 1;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1347 while (*startpos == ' ')
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1348 startpos++;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1349
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1350 /* Get the minor number */
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1351 if ((endpos = strchr (startpos, ' ')) == NULL)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1352 return (-2);
14
83090328581e * More largefile support. Hopefully all that is left is the configure stuff
masneyb
parents: 7
diff changeset
1353 fle->size |= strtol (startpos, NULL, 10) & 0xFF;
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1354 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1355 else
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1356 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1357 /* This is a regular file */
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1358 if ((endpos = strchr (startpos, ' ')) == NULL)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1359 return (-2);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1360 fle->size = strtol (startpos, NULL, 10);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1361 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1362
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1363 /* Skip the blanks till we get to the next entry */
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1364 startpos = endpos + 1;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1365 while (*startpos == ' ')
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1366 startpos++;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1367
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1368 if ((fle->datetime = parse_time (&startpos)) == 0)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1369 return (-2);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1370
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1371 /* Skip the blanks till we get to the next entry */
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1372 startpos = goto_next_token (startpos);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1373
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1374 /* Parse the filename. If this file is a symbolic link, remove the -> part */
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1375 if (fle->attribs[0] == 'l' && ((endpos = strstr (startpos, "->")) != NULL))
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1376 *(endpos - 1) = '\0';
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1377 fle->file = g_malloc (strlen (startpos) + 1);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1378
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1379 strcpy (fle->file, startpos);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1380
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1381 /* Uncomment this if you want to strip the spaces off of the end of the file.
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1382 I don't want to do this by default since there are valid filenames with
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1383 spaces at the end of them. Some broken FTP servers like the Paradyne IPC
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1384 DSLAMS append a bunch of spaces at the end of the file.
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1385 for (endpos = fle->file + strlen (fle->file) - 1;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1386 *endpos == ' ';
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1387 *endpos-- = '\0');
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1388 */
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1389
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1390 return (0);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1391 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1392
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1393
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1394 static int
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1395 gftp_parse_ls_nt (char *str, gftp_file * fle)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1396 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1397 char *startpos;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1398
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1399 startpos = str;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1400 if ((fle->datetime = parse_time (&startpos)) == 0)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1401 return (-2);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1402
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1403 /* No such thing on Windoze.. */
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1404 fle->user = g_malloc (8);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1405 strcpy (fle->user, _("unknown"));
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1406 fle->group = g_malloc (8);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1407 strcpy (fle->group, _("unknown"));
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1408
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1409 startpos = goto_next_token (startpos);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1410 fle->attribs = g_malloc (11);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1411 if (startpos[0] == '<')
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1412 strcpy (fle->attribs, "drwxrwxrwx");
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1413 else
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1414 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1415 strcpy (fle->attribs, "-rw-rw-rw-");
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1416 fle->size = strtol (startpos, NULL, 10);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1417 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1418 startpos = goto_next_token (startpos);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1419 fle->file = g_malloc (strlen (startpos) + 1);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1420 strcpy (fle->file, startpos);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1421 return (0);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1422 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1423
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1424
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1425 static int
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1426 gftp_parse_ls_novell (char *str, gftp_file * fle)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1427 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1428 char *startpos;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1429
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1430 if (str[12] != ' ')
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1431 return (-2);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1432 str[12] = '\0';
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1433 fle->attribs = g_malloc (13);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1434 strcpy (fle->attribs, str);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1435 startpos = str + 13;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1436
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1437 while ((*startpos == ' ' || *startpos == '\t') && *startpos != '\0')
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1438 startpos++;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1439
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1440 if ((startpos = copy_token (&fle->user, startpos)) == NULL)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1441 return (-2);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1442
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1443 fle->group = g_malloc (8);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1444 strcpy (fle->group, _("unknown"));
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1445
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1446 fle->size = strtol (startpos, NULL, 10);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1447
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1448 startpos = goto_next_token (startpos);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1449 if ((fle->datetime = parse_time (&startpos)) == 0)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1450 return (-2);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1451
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1452 startpos = goto_next_token (startpos);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1453 fle->file = g_malloc (strlen (startpos) + 1);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1454 strcpy (fle->file, startpos);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1455 return (0);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1456 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1457
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1458
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1459 static char *
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1460 copy_token (char **dest, char *source)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1461 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1462 /* This function is used internally by gftp_parse_ls () */
39
474d562c7268 2002-10-15 Brian Masney <masneyb@gftp.org>
masneyb
parents: 33
diff changeset
1463 char *endpos, savepos;
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1464
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1465 endpos = source;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1466 while (*endpos != ' ' && *endpos != '\t' && *endpos != '\0')
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1467 endpos++;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1468 if (*endpos == '\0')
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1469 return (NULL);
39
474d562c7268 2002-10-15 Brian Masney <masneyb@gftp.org>
masneyb
parents: 33
diff changeset
1470
474d562c7268 2002-10-15 Brian Masney <masneyb@gftp.org>
masneyb
parents: 33
diff changeset
1471 savepos = *endpos;
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1472 *endpos = '\0';
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1473 *dest = g_malloc (endpos - source + 1);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1474 strcpy (*dest, source);
39
474d562c7268 2002-10-15 Brian Masney <masneyb@gftp.org>
masneyb
parents: 33
diff changeset
1475 *endpos = savepos;
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1476
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1477 /* Skip the blanks till we get to the next entry */
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1478 source = endpos + 1;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1479 while ((*source == ' ' || *source == '\t') && *source != '\0')
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1480 source++;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1481 return (source);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1482 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1483
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1484
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1485 static char *
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1486 goto_next_token (char *pos)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1487 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1488 while (*pos != ' ' && *pos != '\t' && *pos != '\0')
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1489 pos++;
39
474d562c7268 2002-10-15 Brian Masney <masneyb@gftp.org>
masneyb
parents: 33
diff changeset
1490
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1491 if (pos == '\0')
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1492 return (pos);
39
474d562c7268 2002-10-15 Brian Masney <masneyb@gftp.org>
masneyb
parents: 33
diff changeset
1493
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1494 while ((*pos == ' ' || *pos == '\t') && *pos != '\0')
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1495 pos++;
39
474d562c7268 2002-10-15 Brian Masney <masneyb@gftp.org>
masneyb
parents: 33
diff changeset
1496
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1497 return (pos);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1498 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1499
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1500
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1501 static GList *
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1502 gftp_get_dir_listing (gftp_transfer * transfer, int getothdir)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1503 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1504 unsigned long *newsize;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1505 GHashTable * dirhash;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1506 GList * templist;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1507 gftp_file * fle;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1508 char *newname;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1509
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1510 if (getothdir && transfer->toreq)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1511 dirhash = gftp_gen_dir_hash (transfer->toreq);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1512 else
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1513 dirhash = NULL;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1514
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1515 if (gftp_list_files (transfer->fromreq) != 0)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1516 return (NULL);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1517
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1518 fle = g_malloc (sizeof (*fle));
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1519 templist = NULL;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1520 while (gftp_get_next_file (transfer->fromreq, NULL, fle) > 0)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1521 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1522 if (strcmp (fle->file, ".") == 0 || strcmp (fle->file, "..") == 0)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1523 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1524 gftp_file_destroy (fle);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1525 continue;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1526 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1527
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1528 if (dirhash &&
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1529 (newsize = g_hash_table_lookup (dirhash, fle->file)) != NULL)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1530 fle->startsize = *newsize;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1531
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1532 if (transfer->toreq)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1533 fle->destfile = g_strconcat (transfer->toreq->directory, "/",
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1534 fle->file, NULL);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1535 newname = g_strconcat (transfer->fromreq->directory, "/", fle->file, NULL);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1536 g_free (fle->file);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1537 fle->file = newname;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1538
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1539 templist = g_list_append (templist, fle);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1540
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1541 fle = g_malloc (sizeof (*fle));
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1542 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1543 gftp_end_transfer (transfer->fromreq);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1544
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1545 gftp_file_destroy (fle);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1546 g_free (fle);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1547
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1548 if (dirhash)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1549 gftp_destroy_dir_hash (dirhash);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1550
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1551
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1552 return (templist);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1553 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1554
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1555
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1556 int
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1557 gftp_get_all_subdirs (gftp_transfer * transfer,
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1558 void (*update_func) (gftp_transfer * transfer))
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1559 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1560 char *oldfromdir, *oldtodir, *newname;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1561 GList * templist, * lastlist;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1562 int forcecd, remotechanged;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1563 unsigned long *newsize;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1564 GHashTable * dirhash;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1565 gftp_file * curfle;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1566
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1567 g_return_val_if_fail (transfer != NULL, -1);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1568 g_return_val_if_fail (transfer->fromreq != NULL, -1);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1569 g_return_val_if_fail (transfer->files != NULL, -1);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1570
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1571 if (transfer->toreq != NULL)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1572 dirhash = gftp_gen_dir_hash (transfer->toreq);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1573 else
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1574 dirhash = NULL;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1575
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1576 for (lastlist = transfer->files; ; lastlist = lastlist->next)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1577 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1578 curfle = lastlist->data;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1579 if (dirhash &&
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1580 (newsize = g_hash_table_lookup (dirhash, curfle->file)) != NULL)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1581 curfle->startsize = *newsize;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1582
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1583 if (transfer->toreq)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1584 curfle->destfile = g_strconcat (transfer->toreq->directory, "/",
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1585 curfle->file, NULL);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1586 newname = g_strconcat (transfer->fromreq->directory, transfer->fromreq->directory[strlen (transfer->fromreq->directory) - 1] == '/' ? "" : "/", curfle->file, NULL);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1587 g_free (curfle->file);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1588 curfle->file = newname;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1589
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1590 if (lastlist->next == NULL)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1591 break;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1592 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1593
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1594 if (dirhash)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1595 gftp_destroy_dir_hash (dirhash);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1596
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1597 oldfromdir = oldtodir = NULL;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1598 remotechanged = 0;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1599 forcecd = 0;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1600 for (templist = transfer->files; templist != NULL; templist = templist->next)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1601 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1602 curfle = templist->data;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1603
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1604 if (curfle->isdir)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1605 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1606 oldfromdir = transfer->fromreq->directory;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1607 transfer->fromreq->directory = curfle->file;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1608
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1609 if (transfer->toreq)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1610 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1611 oldtodir = transfer->toreq->directory;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1612 transfer->toreq->directory = curfle->destfile;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1613 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1614 forcecd = 1;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1615 if (gftp_set_directory (transfer->fromreq,
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1616 transfer->fromreq->directory) == 0)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1617 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1618 if (curfle->startsize > 0 && transfer->toreq)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1619 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1620 remotechanged = 1;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1621 if (gftp_set_directory (transfer->toreq,
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1622 transfer->toreq->directory) != 0)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1623 curfle->startsize = 0;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1624 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1625
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1626 lastlist->next = gftp_get_dir_listing (transfer,
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1627 curfle->startsize > 0);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1628 if (lastlist->next != NULL)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1629 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1630 lastlist->next->prev = lastlist;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1631 for (; lastlist->next != NULL; lastlist = lastlist->next);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1632 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1633 transfer->numdirs++;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1634 if (update_func)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1635 update_func (transfer);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1636 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1637 else
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1638 curfle->transfer_action = GFTP_TRANS_ACTION_SKIP;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1639
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1640 transfer->fromreq->directory = oldfromdir;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1641 if (transfer->toreq)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1642 transfer->toreq->directory = oldtodir;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1643 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1644 else
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1645 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1646 curfle->ascii = gftp_get_file_transfer_mode (curfle->file,
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1647 transfer->fromreq->data_type) == GFTP_TYPE_ASCII;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1648 transfer->numfiles++;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1649 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1650 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1651
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1652 if (forcecd)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1653 gftp_set_directory (transfer->fromreq, transfer->fromreq->directory);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1654 if (remotechanged && transfer->toreq)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1655 gftp_set_directory (transfer->toreq, transfer->toreq->directory);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1656
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1657 if (update_func)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1658 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1659 transfer->numfiles = transfer->numdirs = -1;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1660 update_func (transfer);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1661 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1662 return (0);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1663 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1664
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1665
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1666 static GHashTable *
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1667 gftp_gen_dir_hash (gftp_request * request)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1668 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1669 unsigned long *newsize;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1670 GHashTable * dirhash;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1671 gftp_file * fle;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1672 char * newname;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1673
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1674
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1675 dirhash = g_hash_table_new (string_hash_function, string_hash_compare);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1676 if (gftp_list_files (request) == 0)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1677 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1678 fle = g_malloc0 (sizeof (*fle));
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1679 while (gftp_get_next_file (request, NULL, fle) > 0)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1680 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1681 newname = fle->file;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1682 newsize = g_malloc (sizeof (unsigned long));
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1683 *newsize = fle->size;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1684 g_hash_table_insert (dirhash, newname, newsize);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1685 fle->file = NULL;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1686 gftp_file_destroy (fle);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1687 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1688 gftp_end_transfer (request);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1689 g_free (fle);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1690 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1691 else
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1692 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1693 g_hash_table_destroy (dirhash);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1694 dirhash = NULL;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1695 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1696 return (dirhash);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1697 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1698
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1699
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1700 static void
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1701 gftp_destroy_dir_hash (GHashTable * dirhash)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1702 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1703 g_hash_table_foreach (dirhash, destroy_hash_ent, NULL);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1704 g_hash_table_destroy (dirhash);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1705 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1706
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1707
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1708 static void
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1709 destroy_hash_ent (gpointer key, gpointer value, gpointer user_data)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1710 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1711
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1712 g_free (key);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1713 g_free (value);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1714 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1715
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1716
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1717 int
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1718 gftp_get_file_transfer_mode (char *filename, int def)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1719 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1720 gftp_file_extensions * tempext;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1721 GList * templist;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1722 int stlen, ret;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1723
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1724 if (!use_default_dl_types)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1725 return (def);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1726
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1727 ret = def;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1728 stlen = strlen (filename);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1729 for (templist = registered_exts; templist != NULL; templist = templist->next)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1730 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1731 tempext = templist->data;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1732
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1733 if (stlen >= tempext->stlen &&
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1734 strcmp (&filename[stlen - tempext->stlen], tempext->ext) == 0)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1735 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1736 if (toupper (*tempext->ascii_binary == 'A'))
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1737 ret = GFTP_TYPE_ASCII;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1738 else if (toupper (*tempext->ascii_binary == 'B'))
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1739 ret = GFTP_TYPE_BINARY;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1740 break;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1741 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1742 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1743
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1744 return (ret);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1745 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1746
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1747
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1748 #if defined (HAVE_GETADDRINFO) && defined (HAVE_GAI_STRERROR)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1749 int
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1750 get_port (struct addrinfo *addr)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1751 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1752 struct sockaddr_in * saddr;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1753 int port;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1754
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1755 if (addr->ai_family == AF_INET)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1756 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1757 saddr = (struct sockaddr_in *) addr->ai_addr;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1758 port = ntohs (saddr->sin_port);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1759 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1760 else
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1761 port = 0;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1762
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1763 return (port);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1764 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1765 #endif
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1766
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1767
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1768 int
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1769 gftp_connect_server (gftp_request * request, char *service)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1770 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1771 char *connect_host, *disphost;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1772 int port, sock;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1773 #if defined (HAVE_GETADDRINFO) && defined (HAVE_GAI_STRERROR)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1774 struct addrinfo hints, *res;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1775 char serv[8];
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1776 int errnum;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1777
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1778 if ((request->use_proxy = gftp_need_proxy (request, service)) < 0)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1779 return (-1);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1780 else if (request->use_proxy == 1)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1781 request->hostp = NULL;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1782
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1783 memset (&hints, 0, sizeof (hints));
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1784 hints.ai_flags = AI_CANONNAME;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1785 hints.ai_family = AF_INET;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1786 hints.ai_socktype = SOCK_STREAM;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1787
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1788 connect_host = request->use_proxy ? request->proxy_hostname :
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1789 request->hostname;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1790 port = request->use_proxy ? request->proxy_port : request->port;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1791
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1792 if (request->hostp == NULL)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1793 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1794 if (port == 0)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1795 strcpy (serv, service);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1796 else
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1797 snprintf (serv, sizeof (serv), "%d", port);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1798
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1799 request->logging_function (gftp_logging_misc, request->user_data,
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1800 _("Looking up %s\n"), connect_host);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1801 if ((errnum = getaddrinfo (connect_host, serv, &hints,
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1802 &request->hostp)) != 0)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1803 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1804 request->logging_function (gftp_logging_error, request->user_data,
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1805 _("Cannot look up hostname %s: %s\n"),
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1806 connect_host, gai_strerror (errnum));
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1807 return (-1);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1808 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1809 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1810
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1811 disphost = connect_host;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1812 for (res = request->hostp; res != NULL; res = res->ai_next)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1813 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1814 disphost = res->ai_canonname ? res->ai_canonname : connect_host;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1815 port = get_port (res);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1816 if ((sock = socket (res->ai_family, res->ai_socktype,
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1817 res->ai_protocol)) < 0)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1818 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1819 request->logging_function (gftp_logging_error, request->user_data,
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1820 _("Failed to create a socket: %s\n"),
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1821 g_strerror (errno));
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1822 continue;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1823 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1824
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1825 request->logging_function (gftp_logging_misc, request->user_data,
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1826 _("Trying %s:%d\n"), disphost, port);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1827
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1828 if (connect (sock, res->ai_addr, res->ai_addrlen) == -1)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1829 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1830 request->logging_function (gftp_logging_error, request->user_data,
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1831 _("Cannot connect to %s: %s\n"),
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1832 disphost, g_strerror (errno));
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1833 close (sock);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1834 continue;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1835 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1836 break;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1837 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1838
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1839 if (res == NULL)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1840 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1841 if (request->hostp != NULL)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1842 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1843 freeaddrinfo (request->hostp);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1844 request->hostp = NULL;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1845 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1846 return (-1);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1847 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1848
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1849 #else /* !HAVE_GETADDRINFO */
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1850 struct sockaddr_in remote_address;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1851 struct servent serv_struct;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1852 int curhost;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1853
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1854 if ((request->use_proxy = gftp_need_proxy (request, service)) < 0)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1855 return (-1);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1856 else if (request->use_proxy == 1)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1857 request->hostp = NULL;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1858
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1859 if ((sock = socket (AF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1860 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1861 request->logging_function (gftp_logging_error, request->user_data,
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1862 _("Failed to create a socket: %s\n"),
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1863 g_strerror (errno));
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1864 return (-1);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1865 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1866
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1867 memset (&remote_address, 0, sizeof (remote_address));
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1868 remote_address.sin_family = AF_INET;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1869
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1870 connect_host = request->use_proxy ? request->proxy_hostname :
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1871 request->hostname;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1872 port = htons (request->use_proxy ? request->proxy_port : request->port);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1873
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1874 if (port == 0)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1875 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1876 if (!r_getservbyname (service, "tcp", &serv_struct, NULL))
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1877 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1878 port = htons (21);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1879 request->port = 21;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1880 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1881 else
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1882 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1883 port = serv_struct.s_port;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1884 request->port = ntohs (serv_struct.s_port);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1885 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1886 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1887 remote_address.sin_port = port;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1888
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1889 if (request->hostp == NULL)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1890 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1891 request->logging_function (gftp_logging_misc, request->user_data,
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1892 _("Looking up %s\n"), connect_host);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1893 if (!(request->hostp = r_gethostbyname (connect_host, &request->host,
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1894 NULL)))
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1895 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1896 request->logging_function (gftp_logging_error, request->user_data,
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1897 _("Cannot look up hostname %s: %s\n"),
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1898 connect_host, g_strerror (errno));
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1899 close (sock);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1900 return (-1);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1901 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1902 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1903
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1904 disphost = NULL;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1905 for (curhost = 0; request->host.h_addr_list[curhost] != NULL; curhost++)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1906 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1907 disphost = request->host.h_name;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1908 memcpy (&remote_address.sin_addr, request->host.h_addr_list[curhost],
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1909 request->host.h_length);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1910 request->logging_function (gftp_logging_misc, request->user_data,
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1911 _("Trying %s:%d\n"),
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1912 request->host.h_name, ntohs (port));
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1913
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1914 if (connect (sock, (struct sockaddr *) &remote_address,
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1915 sizeof (remote_address)) == -1)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1916 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1917 request->logging_function (gftp_logging_error, request->user_data,
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1918 _("Cannot connect to %s: %s\n"),
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1919 connect_host, g_strerror (errno));
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1920 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1921 break;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1922 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1923
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1924 if (request->host.h_addr_list[curhost] == NULL)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1925 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1926 close (sock);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1927 return (-1);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1928 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1929 port = ntohs (port);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1930 #endif /* HAVE_GETADDRINFO */
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1931
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1932 request->logging_function (gftp_logging_misc, request->user_data,
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1933 _("Connected to %s:%d\n"), connect_host, port);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1934 return (sock);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1935 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1936
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1937
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1938 void
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1939 gftp_set_config_options (gftp_request * request)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1940 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1941 request->transfer_type = passive_transfer ? gftp_transfer_passive : gftp_transfer_active;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1942 request->network_timeout = network_timeout;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1943 request->retries = retries;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1944 request->sleep_time = sleep_time;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1945 request->maxkbs = maxkbs;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1946
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1947 if (request->protonum == GFTP_SSHV2_NUM ||
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1948 request->protonum == GFTP_SSH_NUM)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1949 request->need_userpass = ssh_need_userpass;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1950
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1951 /* Set up the proxy server settings. If we are using a HTTP proxy for FTP,
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1952 then set up the HTTP proxy settings */
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1953 if ((strcmp (request->protocol_name, "FTP") == 0 ||
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1954 strcmp (request->protocol_name, "HTTP") == 0) &&
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1955 proxy_config != NULL)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1956 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1957 if (strcmp (request->protocol_name, "FTP") == 0 &&
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1958 strcmp (proxy_config, "http") != 0)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1959 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1960 gftp_set_proxy_hostname (request, firewall_host);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1961 gftp_set_proxy_port (request, firewall_port);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1962 gftp_set_proxy_username (request, firewall_username);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1963 gftp_set_proxy_password (request, firewall_password);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1964 gftp_set_proxy_account (request, firewall_account);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1965 gftp_set_proxy_config (request, proxy_config);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1966 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1967 else
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1968 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1969 gftp_set_proxy_hostname (request, http_proxy_host);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1970 gftp_set_proxy_port (request, http_proxy_port);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1971 gftp_set_proxy_username (request, http_proxy_username);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1972 gftp_set_proxy_password (request, http_proxy_password);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1973
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1974
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1975 if (request->proxy_config == NULL)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1976 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1977 if (strcmp (GFTP_GET_PROTOCOL_NAME (request), "FTP") == 0)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1978 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1979 gftp_protocols[GFTP_HTTP_NUM].init (request);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1980 request->proxy_config = g_malloc (4);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1981 strcpy (request->proxy_config, "ftp");
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1982 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1983 else
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1984 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1985 request->proxy_config = g_malloc (5);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1986 strcpy (request->proxy_config, "http");
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1987 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1988 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1989 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1990 }
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 void
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1995 gftp_set_sftpserv_path (gftp_request * request, char *path)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1996 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1997 g_return_if_fail (request != NULL);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1998
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1999 if (request->sftpserv_path)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
2000 g_free (request->sftpserv_path);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
2001
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
2002 if (path != NULL && *path != '\0')
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
2003 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
2004 request->sftpserv_path = g_malloc (strlen (path) + 1);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
2005 strcpy (request->sftpserv_path, path);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
2006 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
2007 else
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
2008 request->sftpserv_path = NULL;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
2009 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
2010
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
2011
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
2012 void
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
2013 print_file_list (GList * list)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
2014 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
2015 gftp_file * tempfle;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
2016 GList * templist;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
2017
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
2018 printf ("--START OF FILE LISTING - TOP TO BOTTOM--\n");
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
2019 for (templist = list; ; templist = templist->next)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
2020 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
2021 tempfle = templist->data;
14
83090328581e * More largefile support. Hopefully all that is left is the configure stuff
masneyb
parents: 7
diff changeset
2022 #if defined (_LARGEFILE_SOURCE)
83090328581e * More largefile support. Hopefully all that is left is the configure stuff
masneyb
parents: 7
diff changeset
2023 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
2024 #else
83090328581e * More largefile support. Hopefully all that is left is the configure stuff
masneyb
parents: 7
diff changeset
2025 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
2026 #endif
16
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
2027 tempfle->file, tempfle->destfile,
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
2028 tempfle->size, tempfle->startsize,
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
2029 tempfle->user, tempfle->group, tempfle->attribs);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
2030 if (templist->next == NULL)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
2031 break;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
2032 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
2033
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
2034 printf ("--START OF FILE LISTING - BOTTOM TO TOP--\n");
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
2035 for (; ; templist = templist->prev)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
2036 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
2037 tempfle = templist->data;
14
83090328581e * More largefile support. Hopefully all that is left is the configure stuff
masneyb
parents: 7
diff changeset
2038 #if defined (_LARGEFILE_SOURCE)
83090328581e * More largefile support. Hopefully all that is left is the configure stuff
masneyb
parents: 7
diff changeset
2039 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
2040 #else
83090328581e * More largefile support. Hopefully all that is left is the configure stuff
masneyb
parents: 7
diff changeset
2041 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
2042 #endif
16
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
2043 tempfle->file, tempfle->destfile,
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
2044 tempfle->size, tempfle->startsize,
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
2045 tempfle->user, tempfle->group, tempfle->attribs);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
2046 if (templist == list)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
2047 break;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
2048 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
2049 printf ("--END OF FILE LISTING--\n");
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
2050 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
2051
41
4bcfaf6307b5 2002-10-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
2052
4bcfaf6307b5 2002-10-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
2053 char *
4bcfaf6307b5 2002-10-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
2054 gftp_fgets (gftp_request * request, char * str, size_t len, FILE * fd)
4bcfaf6307b5 2002-10-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
2055 {
4bcfaf6307b5 2002-10-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
2056 char * ret = NULL;
4bcfaf6307b5 2002-10-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
2057
4bcfaf6307b5 2002-10-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
2058 errno = 0;
4bcfaf6307b5 2002-10-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
2059 do
4bcfaf6307b5 2002-10-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
2060 {
4bcfaf6307b5 2002-10-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
2061 ret = fgets (str, len, fd);
4bcfaf6307b5 2002-10-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
2062 if (ferror (fd))
4bcfaf6307b5 2002-10-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
2063 {
4bcfaf6307b5 2002-10-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
2064 if (errno == EINTR)
4bcfaf6307b5 2002-10-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
2065 {
4bcfaf6307b5 2002-10-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
2066 clearerr (fd);
4bcfaf6307b5 2002-10-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
2067 if (request->cancel)
4bcfaf6307b5 2002-10-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
2068 break;
4bcfaf6307b5 2002-10-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
2069 else
4bcfaf6307b5 2002-10-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
2070 continue;
4bcfaf6307b5 2002-10-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
2071 }
4bcfaf6307b5 2002-10-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
2072
4bcfaf6307b5 2002-10-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
2073 request->logging_function (gftp_logging_error, request->user_data,
4bcfaf6307b5 2002-10-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
2074 _("Error: Could not read from socket: %s\n"),
4bcfaf6307b5 2002-10-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
2075 g_strerror (errno));
4bcfaf6307b5 2002-10-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
2076 gftp_disconnect (request);
4bcfaf6307b5 2002-10-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
2077 return (NULL);
4bcfaf6307b5 2002-10-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
2078 }
4bcfaf6307b5 2002-10-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
2079 }
4bcfaf6307b5 2002-10-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
2080 while (errno == EINTR && !request->cancel);
4bcfaf6307b5 2002-10-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
2081
4bcfaf6307b5 2002-10-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
2082 if (errno == EINTR && request->cancel)
4bcfaf6307b5 2002-10-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
2083 {
4bcfaf6307b5 2002-10-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
2084 gftp_disconnect (request);
4bcfaf6307b5 2002-10-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
2085 return (NULL);
4bcfaf6307b5 2002-10-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
2086 }
4bcfaf6307b5 2002-10-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
2087
4bcfaf6307b5 2002-10-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
2088 return (ret);
4bcfaf6307b5 2002-10-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
2089 }
4bcfaf6307b5 2002-10-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
2090
4bcfaf6307b5 2002-10-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
2091
4bcfaf6307b5 2002-10-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
2092 size_t
4bcfaf6307b5 2002-10-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
2093 gftp_fwrite (gftp_request * request, const void *ptr, size_t size, FILE * fd)
4bcfaf6307b5 2002-10-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
2094 {
4bcfaf6307b5 2002-10-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
2095 size_t ret;
4bcfaf6307b5 2002-10-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
2096
4bcfaf6307b5 2002-10-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
2097 errno = 0;
4bcfaf6307b5 2002-10-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
2098 ret = 0;
4bcfaf6307b5 2002-10-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
2099 do
4bcfaf6307b5 2002-10-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
2100 {
4bcfaf6307b5 2002-10-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
2101 ret = fwrite (ptr, size, 1, fd);
4bcfaf6307b5 2002-10-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
2102 if (ferror (fd))
4bcfaf6307b5 2002-10-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
2103 {
4bcfaf6307b5 2002-10-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
2104 if (errno == EINTR)
4bcfaf6307b5 2002-10-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
2105 {
4bcfaf6307b5 2002-10-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
2106 if (request->cancel)
4bcfaf6307b5 2002-10-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
2107 break;
4bcfaf6307b5 2002-10-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
2108 else
4bcfaf6307b5 2002-10-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
2109 {
4bcfaf6307b5 2002-10-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
2110 clearerr (fd);
4bcfaf6307b5 2002-10-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
2111 continue;
4bcfaf6307b5 2002-10-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
2112 }
4bcfaf6307b5 2002-10-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
2113 }
4bcfaf6307b5 2002-10-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
2114
4bcfaf6307b5 2002-10-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
2115 request->logging_function (gftp_logging_error, request->user_data,
4bcfaf6307b5 2002-10-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
2116 _("Error: Could not write to socket: %s\n"),
4bcfaf6307b5 2002-10-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
2117 g_strerror (errno));
4bcfaf6307b5 2002-10-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
2118 gftp_disconnect (request);
4bcfaf6307b5 2002-10-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
2119 return (-1);
4bcfaf6307b5 2002-10-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
2120 }
4bcfaf6307b5 2002-10-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
2121
4bcfaf6307b5 2002-10-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
2122 fflush (request->sockfd_write);
4bcfaf6307b5 2002-10-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
2123 if (ferror (fd))
4bcfaf6307b5 2002-10-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
2124 {
4bcfaf6307b5 2002-10-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
2125 if (errno == EINTR)
4bcfaf6307b5 2002-10-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
2126 {
4bcfaf6307b5 2002-10-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
2127 if (request->cancel)
4bcfaf6307b5 2002-10-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
2128 break;
4bcfaf6307b5 2002-10-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
2129 else
4bcfaf6307b5 2002-10-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
2130 {
4bcfaf6307b5 2002-10-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
2131 clearerr (fd);
4bcfaf6307b5 2002-10-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
2132 continue;
4bcfaf6307b5 2002-10-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
2133 }
4bcfaf6307b5 2002-10-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
2134 }
4bcfaf6307b5 2002-10-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
2135
4bcfaf6307b5 2002-10-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
2136 request->logging_function (gftp_logging_error, request->user_data,
4bcfaf6307b5 2002-10-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
2137 _("Error: Could not write to socket: %s\n"),
4bcfaf6307b5 2002-10-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
2138 g_strerror (errno));
4bcfaf6307b5 2002-10-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
2139 gftp_disconnect (request);
4bcfaf6307b5 2002-10-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
2140 return (-1);
4bcfaf6307b5 2002-10-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
2141 }
4bcfaf6307b5 2002-10-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
2142 }
4bcfaf6307b5 2002-10-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
2143 while (errno == EINTR && !request->cancel);
4bcfaf6307b5 2002-10-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
2144
4bcfaf6307b5 2002-10-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
2145 if (errno == EINTR && request->cancel)
4bcfaf6307b5 2002-10-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
2146 {
4bcfaf6307b5 2002-10-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
2147 gftp_disconnect (request);
4bcfaf6307b5 2002-10-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
2148 return (-1);
4bcfaf6307b5 2002-10-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
2149 }
4bcfaf6307b5 2002-10-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
2150
4bcfaf6307b5 2002-10-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
2151 return (ret);
4bcfaf6307b5 2002-10-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
2152 }
4bcfaf6307b5 2002-10-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 40
diff changeset
2153