annotate lib/protocols.c @ 1:8b1883341c6f

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