annotate lib/protocols.c @ 937:b105f2f6f5a4

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