annotate lib/misc.c @ 91:8c37d73d3f1f

2003-1-21 Brian Masney <masneyb@gftp.org> * lib/gftp.h - added server type defines. Added server_type field to gftp_request * lib/local.c - use S_ISDIR and S_ISLINK macros * lib/protocols.c - (gftp_parse_ls*) - use hints from server_type for parsing directory listing * lib/rfc959.c - added function rfc959_syst. Call this on startup * lib/protocols.c lib/rfc959.c lib/sshv2.c - pass request structure to gftp_parse_ls * lib/sshv2.c - set server_type to be GFTP_TYPE_UNIX
author masneyb
date Tue, 21 Jan 2003 23:46:03 +0000
parents 6df043359b41
children 3b573c8ef706
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 /* misc.c - general purpose routines */
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
3 /* Copyright (C) 1998-2002 Brian Masney <masneyb@gftp.org> */
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
4 /* */
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
5 /* This program is free software; you can redistribute it and/or modify */
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
6 /* it under the terms of the GNU General Public License as published by */
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
7 /* the Free Software Foundation; either version 2 of the License, or */
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
8 /* (at your option) any later version. */
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
9 /* */
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
10 /* This program is distributed in the hope that it will be useful, */
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
11 /* but WITHOUT ANY WARRANTY; without even the implied warranty of */
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
12 /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
13 /* GNU General Public License for more details. */
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
14 /* */
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
15 /* You should have received a copy of the GNU General Public License */
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
16 /* along with this program; if not, write to the Free Software */
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
17 /* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111 USA */
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
18 /*****************************************************************************/
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
19
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
20 #include "gftp.h"
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
21 #include "options.h"
33
c8ec7877432e 2002-10-06 Brian Masney <masneyb@gftp.org>
masneyb
parents: 16
diff changeset
22 static const char cvsid[] = "$Id$";
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
23
87
6df043359b41 2003-1-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 84
diff changeset
24 /* FIXME - this isn't right for all locales. Use glib's printf instead */
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
25 char *
14
83090328581e * More largefile support. Hopefully all that is left is the configure stuff
masneyb
parents: 13
diff changeset
26 insert_commas (off_t number, char *dest_str, size_t dest_len)
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
27 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
28 char *frompos, *topos, src[50], *dest;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
29 int len, num, rem, i;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
30
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
31 if (dest_str != NULL)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
32 *dest_str = '\0';
56
a12bcbc2fce4 2002-11-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
33 len = (number > 0 ? log10 (number) : 0) + 2;
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
34
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
35 if (len <= 0)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
36 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
37 if (dest_str != NULL)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
38 strncpy (dest_str, "0", dest_len);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
39 else
56
a12bcbc2fce4 2002-11-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
40 dest_str = g_strdup ("0");
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
41 return (dest_str);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
42 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
43
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
44 len += len / 3;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
45 if (dest_str != NULL && len > dest_len)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
46 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
47
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
48 for (i=0; i<dest_len - 1; i++)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
49 dest_str[i] = 'X';
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
50 dest_str[dest_len - 1] = '\0';
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
51 return (dest_str);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
52 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
53
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
54 if (dest_str == NULL)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
55 dest = g_malloc0 (len);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
56 else
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
57 dest = dest_str;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
58
14
83090328581e * More largefile support. Hopefully all that is left is the configure stuff
masneyb
parents: 13
diff changeset
59 #if defined (_LARGEFILE_SOURCE)
83090328581e * More largefile support. Hopefully all that is left is the configure stuff
masneyb
parents: 13
diff changeset
60 g_snprintf (src, sizeof (src), "%lld", number);
83090328581e * More largefile support. Hopefully all that is left is the configure stuff
masneyb
parents: 13
diff changeset
61 #else
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
62 g_snprintf (src, sizeof (src), "%ld", number);
14
83090328581e * More largefile support. Hopefully all that is left is the configure stuff
masneyb
parents: 13
diff changeset
63 #endif
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
64
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
65 num = strlen (src) / 3 - 1;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
66 rem = strlen (src) % 3;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
67 frompos = src;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
68 topos = dest;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
69 for (i = 0; i < rem; i++)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
70 *topos++ = *frompos++;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
71
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
72 if (*frompos != '\0')
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
73 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
74 if (rem != 0)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
75 *topos++ = ',';
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
76 while (num > 0)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
77 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
78 for (i = 0; i < 3; i++)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
79 *topos++ = *frompos++;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
80 *topos++ = ',';
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
81 num--;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
82 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
83 for (i = 0; i < 3; i++)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
84 *topos++ = *frompos++;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
85 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
86 *topos = '\0';
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
87 return (dest);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
88 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
89
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
90
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
91 char *
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
92 alltrim (char *str)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
93 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
94 char *pos, *newpos;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
95 int diff;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
96
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
97 pos = str + strlen (str) - 1;
87
6df043359b41 2003-1-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 84
diff changeset
98 while (pos >= str && (*pos == ' ' || *pos == '\t'))
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
99 *pos-- = '\0';
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
100
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
101 pos = str;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
102 diff = 0;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
103 while (*pos++ == ' ')
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
104 diff++;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
105
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
106 if (diff == 0)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
107 return (str);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
108
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
109 pos = str + diff;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
110 newpos = str;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
111 while (*pos != '\0')
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
112 *newpos++ = *pos++;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
113 *newpos = '\0';
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
114
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
115 return (str);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
116 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
117
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
118
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
119 char *
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
120 expand_path (const char *src)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
121 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
122 char *str, *pos, *endpos, *prevpos, *newstr, *tempstr, tempchar;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
123 struct passwd *pw;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
124
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
125 pw = NULL;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
126 str = g_malloc (strlen (src) + 1);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
127 strcpy (str, src);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
128
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
129 if (*str == '~')
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
130 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
131 if (*(str + 1) == '/' || *(str + 1) == '\0')
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
132 pw = getpwuid (geteuid ());
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
133 else
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
134 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
135 if ((pos = strchr (str, '/')) != NULL)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
136 *pos = '\0';
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
137
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
138 pw = getpwnam (str + 1);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
139
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
140 if (pos != NULL)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
141 *pos = '/';
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
142 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
143 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
144
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
145 endpos = str;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
146 newstr = NULL;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
147 while ((pos = strchr (endpos, '/')) != NULL)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
148 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
149 pos++;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
150 while (*pos == '/')
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
151 pos++;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
152 if ((endpos = strchr (pos, '/')) == NULL)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
153 endpos = pos + strlen (pos);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
154 tempchar = *endpos;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
155 *endpos = '\0';
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
156 if (strcmp (pos, "..") == 0)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
157 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
158 *(pos - 1) = '\0';
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
159 if (newstr != NULL && (prevpos = strrchr (newstr, '/')) != NULL)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
160 *prevpos = '\0';
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
161 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
162 else if (strcmp (pos, ".") != 0)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
163 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
164 if (newstr == NULL)
56
a12bcbc2fce4 2002-11-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
165 newstr = g_strdup (pos - 1);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
166 else
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
167 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
168 tempstr = g_strconcat (newstr, pos - 1, NULL);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
169 g_free (newstr);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
170 newstr = tempstr;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
171 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
172 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
173 *endpos = tempchar;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
174 if (*endpos == '\0')
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
175 break;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
176 endpos = pos + 1;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
177 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
178
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
179 if (newstr == NULL || *newstr == '\0')
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
180 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
181 if (newstr != NULL)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
182 g_free (newstr);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
183 newstr = g_malloc0 (2);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
184 *newstr = '/';
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
185 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
186
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
187 g_free (str);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
188
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
189 if (pw != NULL)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
190 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
191 if ((pos = strchr (newstr, '/')) == NULL)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
192 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
193 str = g_malloc (strlen (pw->pw_dir) + 1);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
194 strcpy (str, pw->pw_dir);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
195 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
196 else
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
197 str = g_strconcat (pw->pw_dir, pos, NULL);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
198
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
199 g_free (newstr);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
200 newstr = str;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
201 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
202
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
203 return (newstr);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
204 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
205
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
206
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
207 void
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
208 remove_double_slashes (char *string)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
209 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
210 char *newpos, *oldpos;
87
6df043359b41 2003-1-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 84
diff changeset
211 size_t len;
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
212
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
213 oldpos = newpos = string;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
214 while (*oldpos != '\0')
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
215 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
216 *newpos++ = *oldpos++;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
217 if (*oldpos == '\0')
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
218 break;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
219 while (*(newpos - 1) == '/' && *(oldpos) == '/')
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
220 oldpos++;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
221 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
222 *newpos = '\0';
87
6df043359b41 2003-1-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 84
diff changeset
223
6df043359b41 2003-1-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 84
diff changeset
224 len = strlen (string);
6df043359b41 2003-1-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 84
diff changeset
225 if (string[len - 1] == '/')
6df043359b41 2003-1-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 84
diff changeset
226 string[len - 1] = '\0';
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
227 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
228
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
229
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
230 void
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
231 make_nonnull (char **str)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
232 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
233 if (*str == NULL)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
234 *str = g_malloc0 (1);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
235 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
236
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
237
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
238 int
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
239 copyfile (char *source, char *dest)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
240 {
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
241 int srcfd, destfd;
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
242 char buf[8192];
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
243 ssize_t n;
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
244
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
245 if ((srcfd = open (source, O_RDONLY)) == -1)
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
246 {
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
247 printf (_("Error: Cannot open local file %s: %s\n"),
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
248 source, g_strerror (errno));
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
249 exit (1);
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
250 }
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
251
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
252 if ((destfd = open (dest, O_WRONLY | O_CREAT, S_IRUSR | S_IWUSR)) == -1)
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
253 {
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
254 printf (_("Error: Cannot open local file %s: %s\n"),
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
255 dest, g_strerror (errno));
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
256 close (srcfd);
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
257 exit (1);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
258 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
259
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
260 while ((n = read (srcfd, buf, sizeof (buf))) > 0)
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
261 {
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
262 if (write (destfd, buf, n) == -1)
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
263 {
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
264 printf (_("Error: Could not write to socket: %s\n"),
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
265 g_strerror (errno));
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
266 exit (1);
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
267 }
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
268 }
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
269
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
270 if (n == -1)
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
271 {
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
272 printf (_("Error: Could not read from socket: %s\n"), g_strerror (errno));
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
273 exit (1);
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
274 }
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
275
87
6df043359b41 2003-1-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 84
diff changeset
276 if (close (srcfd) == -1)
6df043359b41 2003-1-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 84
diff changeset
277 {
6df043359b41 2003-1-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 84
diff changeset
278 printf (_("Error closing file descriptor: %s\n"), g_strerror (errno));
6df043359b41 2003-1-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 84
diff changeset
279 exit (1);
6df043359b41 2003-1-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 84
diff changeset
280 }
6df043359b41 2003-1-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 84
diff changeset
281
6df043359b41 2003-1-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 84
diff changeset
282 if (close (destfd) == -1)
6df043359b41 2003-1-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 84
diff changeset
283 {
6df043359b41 2003-1-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 84
diff changeset
284 printf (_("Error closing file descriptor: %s\n"), g_strerror (errno));
6df043359b41 2003-1-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 84
diff changeset
285 exit (1);
6df043359b41 2003-1-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 84
diff changeset
286 }
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
287
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
288 return (1);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
289 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
290
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
291
87
6df043359b41 2003-1-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 84
diff changeset
292 /* FIXME - is there a replacement for this */
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
293 int
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
294 gftp_match_filespec (char *filename, char *filespec)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
295 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
296 char *filepos, *wcpos, *pos, *newpos, search_str[20];
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
297 size_t len, curlen;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
298
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
299 if (filename == NULL || *filename == '\0' ||
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
300 filespec == NULL || *filespec == '\0')
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
301 return(1);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
302
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
303 filepos = filename;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
304 wcpos = filespec;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
305 while(1)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
306 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
307 if (*wcpos == '\0')
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
308 return (1);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
309 else if (*filepos == '\0')
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
310 return(0);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
311 else if(*wcpos == '?')
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
312 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
313 wcpos++;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
314 filepos++;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
315 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
316 else if(*wcpos == '*' && *(wcpos+1) == '\0')
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
317 return(1);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
318 else if(*wcpos == '*')
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
319 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
320 len = sizeof (search_str);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
321 for (pos = wcpos + 1, newpos = search_str, curlen = 0;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
322 *pos != '*' && *pos != '?' && *pos != '\0' && curlen < len;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
323 curlen++, *newpos++ = *pos++);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
324 *newpos = '\0';
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
325
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
326 if ((filepos = strstr (filepos, search_str)) == NULL)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
327 return(0);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
328 wcpos += curlen + 1;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
329 filepos += curlen;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
330 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
331 else if(*wcpos++ != *filepos++)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
332 return(0);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
333 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
334 return (1);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
335 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
336
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
337
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
338 int
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
339 gftp_parse_command_line (int *argc, char ***argv)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
340 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
341 if (*argc > 1)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
342 {
87
6df043359b41 2003-1-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 84
diff changeset
343 if (strcmp (argv[0][1], "--help") == 0 ||
6df043359b41 2003-1-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 84
diff changeset
344 strcmp (argv[0][1], "-h") == 0)
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
345 gftp_usage ();
87
6df043359b41 2003-1-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 84
diff changeset
346 else if (strcmp (argv[0][1], "--version") == 0 ||
6df043359b41 2003-1-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 84
diff changeset
347 strcmp (argv[0][1], "-v") == 0)
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
348 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
349 printf ("%s\n", version);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
350 exit (0);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
351 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
352 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
353 return (0);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
354 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
355
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
356
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
357 void
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
358 gftp_usage (void)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
359 {
87
6df043359b41 2003-1-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 84
diff changeset
360 printf (_("usage: gftp [[protocol://][user:[pass]@]site[:port][/directory]]\n"));
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
361 exit (0);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
362 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
363
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
364
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
365 char *
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
366 get_xpm_path (char *filename, int quit_on_err)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
367 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
368 char *tempstr, *exfile;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
369
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
370 tempstr = g_strconcat (BASE_CONF_DIR, "/", filename, NULL);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
371 exfile = expand_path (tempstr);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
372 g_free (tempstr);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
373 if (access (exfile, F_OK) != 0)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
374 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
375 g_free (exfile);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
376 tempstr = g_strconcat (SHARE_DIR, "/", filename, NULL);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
377 exfile = expand_path (tempstr);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
378 g_free (tempstr);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
379 if (access (exfile, F_OK) != 0)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
380 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
381 g_free (exfile);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
382 exfile = g_strconcat ("/usr/share/icons/", filename, NULL);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
383 if (access (exfile, F_OK) != 0)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
384 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
385 g_free (exfile);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
386 if (!quit_on_err)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
387 return (NULL);
87
6df043359b41 2003-1-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 84
diff changeset
388
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
389 printf (_("gFTP Error: Cannot find file %s in %s or %s\n"),
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
390 filename, SHARE_DIR, BASE_CONF_DIR);
87
6df043359b41 2003-1-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 84
diff changeset
391 exit (1);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
392 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
393 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
394 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
395 return (exfile);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
396 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
397
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
398
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
399 gint
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
400 string_hash_compare (gconstpointer path1, gconstpointer path2)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
401 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
402 return (strcmp ((char *) path1, (char *) path2) == 0);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
403 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
404
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
405
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
406 guint
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
407 string_hash_function (gconstpointer key)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
408 {
59
618423504fe0 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 58
diff changeset
409 guint ret;
618423504fe0 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 58
diff changeset
410 int i;
618423504fe0 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 58
diff changeset
411
618423504fe0 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 58
diff changeset
412 ret = 0;
87
6df043359b41 2003-1-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 84
diff changeset
413 for (i=0; ((char *) key)[i] != '\0' && i < 3; i++)
59
618423504fe0 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 58
diff changeset
414 ret += ((char *) key)[i];
618423504fe0 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 58
diff changeset
415
618423504fe0 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 58
diff changeset
416 return (ret);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
417 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
418
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
419
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
420 void
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
421 free_file_list (GList * filelist)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
422 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
423 gftp_file * tempfle;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
424 GList * templist;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
425
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
426 templist = filelist;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
427 while (templist != NULL)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
428 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
429 tempfle = templist->data;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
430 free_fdata (tempfle);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
431 templist = templist->next;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
432 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
433 g_list_free (filelist);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
434 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
435
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
436
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
437 void
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
438 free_fdata (gftp_file * fle)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
439 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
440 if (fle->file)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
441 g_free (fle->file);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
442 if (fle->user)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
443 g_free (fle->user);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
444 if (fle->group)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
445 g_free (fle->group);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
446 if (fle->attribs)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
447 g_free (fle->attribs);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
448 if (fle->destfile)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
449 g_free (fle->destfile);
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
450 if (fle->fd > 0)
87
6df043359b41 2003-1-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 84
diff changeset
451 close (fle->fd); /* FIXME - need to log a failure */
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
452 g_free (fle);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
453 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
454
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
455
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
456 gftp_file *
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
457 copy_fdata (gftp_file * fle)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
458 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
459 gftp_file * newfle;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
460
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
461 newfle = g_malloc0 (sizeof (*newfle));
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
462 memcpy (newfle, fle, sizeof (*newfle));
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
463
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
464 if (fle->file)
87
6df043359b41 2003-1-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 84
diff changeset
465 newfle->file = g_strdup (fle->file);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
466
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
467 if (fle->user)
87
6df043359b41 2003-1-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 84
diff changeset
468 newfle->user = g_strdup (fle->user);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
469
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
470 if (fle->group)
87
6df043359b41 2003-1-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 84
diff changeset
471 newfle->group = g_strdup (fle->group);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
472
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
473 if (fle->attribs)
87
6df043359b41 2003-1-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 84
diff changeset
474 newfle->attribs = g_strdup (fle->attribs);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
475
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
476 if (fle->destfile)
87
6df043359b41 2003-1-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 84
diff changeset
477 newfle->destfile = g_strdup (fle->destfile);
6df043359b41 2003-1-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 84
diff changeset
478
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
479 return (newfle);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
480 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
481
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
482
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
483 int
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
484 compare_request (gftp_request * request1, gftp_request * request2,
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
485 int compare_dirs)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
486 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
487 char *strarr[3][2];
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
488 int i, ret;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
489
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
490 ret = 1;
87
6df043359b41 2003-1-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 84
diff changeset
491 if (request1->protonum == request2->protonum &&
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
492 request1->port == request2->port)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
493 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
494 strarr[0][0] = request1->hostname;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
495 strarr[0][1] = request2->hostname;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
496 strarr[1][0] = request1->username;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
497 strarr[1][1] = request2->username;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
498 if (compare_dirs)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
499 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
500 strarr[2][0] = request1->directory;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
501 strarr[2][1] = request2->directory;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
502 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
503 else
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
504 strarr[2][0] = strarr[2][1] = "";
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
505
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
506 for (i = 0; i < 3; i++)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
507 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
508 if ((strarr[i][0] && !strarr[i][1]) ||
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
509 (!strarr[i][0] && strarr[i][1]))
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
510 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
511 ret = 0;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
512 break;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
513 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
514
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
515 if (strarr[i][0] && strarr[i][1] &&
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
516 strcmp (strarr[i][0], strarr[i][1]) != 0)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
517 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
518 ret = 0;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
519 break;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
520 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
521 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
522 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
523 else
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
524 ret = 0;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
525 return (ret);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
526 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
527
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
528
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
529 void
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
530 free_tdata (gftp_transfer * tdata)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
531 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
532 if (tdata->statmutex)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
533 g_free (tdata->statmutex);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
534 if (tdata->structmutex)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
535 g_free (tdata->structmutex);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
536 if (tdata->fromreq != NULL)
67
aa971a4bb16f 2002-11-27 Brian Masney <masneyb@gftp.org>
masneyb
parents: 66
diff changeset
537 gftp_request_destroy (tdata->fromreq, 1);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
538 if (tdata->toreq != NULL)
67
aa971a4bb16f 2002-11-27 Brian Masney <masneyb@gftp.org>
masneyb
parents: 66
diff changeset
539 gftp_request_destroy (tdata->toreq, 1);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
540 free_file_list (tdata->files);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
541 g_free (tdata);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
542 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
543
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
544
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
545 gftp_request *
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
546 copy_request (gftp_request * req)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
547 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
548 gftp_request * newreq;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
549
66
cd3e457cbc85 2002-11-26 Brian Masney <masneyb@gftp.org>
masneyb
parents: 65
diff changeset
550 newreq = gftp_request_new ();
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
551
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
552 if (req->hostname)
56
a12bcbc2fce4 2002-11-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
553 newreq->hostname = g_strdup (req->hostname);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
554 if (req->username)
56
a12bcbc2fce4 2002-11-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
555 newreq->username = g_strdup (req->username);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
556 if (req->password)
56
a12bcbc2fce4 2002-11-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
557 newreq->password = g_strdup (req->password);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
558 if (req->account)
56
a12bcbc2fce4 2002-11-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
559 newreq->account = g_strdup (req->account);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
560 if (req->directory)
56
a12bcbc2fce4 2002-11-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
561 newreq->directory = g_strdup (req->directory);
66
cd3e457cbc85 2002-11-26 Brian Masney <masneyb@gftp.org>
masneyb
parents: 65
diff changeset
562 newreq->port = req->port;
cd3e457cbc85 2002-11-26 Brian Masney <masneyb@gftp.org>
masneyb
parents: 65
diff changeset
563 newreq->data_type = req->data_type;
cd3e457cbc85 2002-11-26 Brian Masney <masneyb@gftp.org>
masneyb
parents: 65
diff changeset
564 newreq->use_proxy = req->use_proxy;
cd3e457cbc85 2002-11-26 Brian Masney <masneyb@gftp.org>
masneyb
parents: 65
diff changeset
565 gftp_set_proxy_config (newreq, req->proxy_config);
cd3e457cbc85 2002-11-26 Brian Masney <masneyb@gftp.org>
masneyb
parents: 65
diff changeset
566 newreq->transfer_type = req->transfer_type;
cd3e457cbc85 2002-11-26 Brian Masney <masneyb@gftp.org>
masneyb
parents: 65
diff changeset
567 newreq->network_timeout = req->network_timeout;
cd3e457cbc85 2002-11-26 Brian Masney <masneyb@gftp.org>
masneyb
parents: 65
diff changeset
568 newreq->retries = req->retries;
cd3e457cbc85 2002-11-26 Brian Masney <masneyb@gftp.org>
masneyb
parents: 65
diff changeset
569 newreq->sleep_time = req->sleep_time;
cd3e457cbc85 2002-11-26 Brian Masney <masneyb@gftp.org>
masneyb
parents: 65
diff changeset
570 newreq->passive_transfer = req->passive_transfer;
cd3e457cbc85 2002-11-26 Brian Masney <masneyb@gftp.org>
masneyb
parents: 65
diff changeset
571 newreq->maxkbs = req->maxkbs;
cd3e457cbc85 2002-11-26 Brian Masney <masneyb@gftp.org>
masneyb
parents: 65
diff changeset
572 newreq->logging_function = req->logging_function;
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
573
66
cd3e457cbc85 2002-11-26 Brian Masney <masneyb@gftp.org>
masneyb
parents: 65
diff changeset
574 if (req->sftpserv_path != NULL)
cd3e457cbc85 2002-11-26 Brian Masney <masneyb@gftp.org>
masneyb
parents: 65
diff changeset
575 newreq->sftpserv_path = g_strdup (req->sftpserv_path);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
576
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
577 req->init (newreq);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
578
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
579 return (newreq);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
580 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
581
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
582
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
583 int
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
584 ptym_open (char *pts_name)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
585 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
586 int fd;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
587
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
588 #ifdef __sgi
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
589 char *tempstr;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
590
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
591 if ((tempstr = _getpty (&fd, O_RDWR, 0600, 0)) == NULL)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
592 return (-1);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
593
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
594 strcpy (pts_name, tempstr);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
595 return (fd);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
596
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
597 #else /* !__sgi */
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
598
80
f4f6f44225d3 2002-12-10 Brian Masney <masneyb@gftp.org>
masneyb
parents: 77
diff changeset
599 #ifdef HAVE_GRANTPT
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
600
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
601 char *tempstr;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
602
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
603 strcpy (pts_name, "/dev/ptmx");
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
604 if ((fd = open (pts_name, O_RDWR)) < 0)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
605 return (-1);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
606
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
607 if (grantpt (fd) < 0)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
608 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
609 close (fd);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
610 return (-1);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
611 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
612
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
613 if (unlockpt (fd) < 0)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
614 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
615 close (fd);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
616 return (-1);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
617 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
618
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
619 if ((tempstr = ptsname (fd)) == NULL)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
620 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
621 close (fd);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
622 return (-1);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
623 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
624
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
625 strcpy (pts_name, tempstr);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
626 return (fd);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
627
80
f4f6f44225d3 2002-12-10 Brian Masney <masneyb@gftp.org>
masneyb
parents: 77
diff changeset
628 #else /* !GRANTPT */
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
629
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
630 char *pos1, *pos2;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
631
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
632 strcpy (pts_name, "/dev/ptyXY");
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
633 for (pos1 = "pqrstuvwxyzPQRST"; *pos1 != '\0'; pos1++)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
634 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
635 pts_name[8] = *pos1;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
636 for (pos2 = "0123456789abcdef"; *pos2 != '\0'; pos2++)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
637 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
638 pts_name[9] = *pos2;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
639 if ((fd = open (pts_name, O_RDWR)) < 0)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
640 continue;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
641 pts_name[5] = 't';
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
642 return (fd);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
643 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
644 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
645 return (-1);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
646
87
6df043359b41 2003-1-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 84
diff changeset
647 #endif /* GRANTPT */
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
648
87
6df043359b41 2003-1-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 84
diff changeset
649 #endif /* __sgi */
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
650
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
651 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
652
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
653
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
654 int
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
655 ptys_open (int fdm, char *pts_name)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
656 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
657 int fds;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
658
80
f4f6f44225d3 2002-12-10 Brian Masney <masneyb@gftp.org>
masneyb
parents: 77
diff changeset
659 #if !defined (HAVE_GRANTPT) && !defined (__sgi)
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
660
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
661 chmod (pts_name, S_IRUSR | S_IWUSR);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
662 chown (pts_name, getuid (), -1);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
663
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
664 #endif
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
665
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
666 if ((fds = open (pts_name, O_RDWR)) < 0)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
667 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
668 close (fdm);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
669 return (-1);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
670 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
671
80
f4f6f44225d3 2002-12-10 Brian Masney <masneyb@gftp.org>
masneyb
parents: 77
diff changeset
672 #ifdef HAVE_GRANTPT
f4f6f44225d3 2002-12-10 Brian Masney <masneyb@gftp.org>
masneyb
parents: 77
diff changeset
673 /* I intentionally ignore these errors */
f4f6f44225d3 2002-12-10 Brian Masney <masneyb@gftp.org>
masneyb
parents: 77
diff changeset
674 ioctl (fds, I_PUSH, "ptem");
f4f6f44225d3 2002-12-10 Brian Masney <masneyb@gftp.org>
masneyb
parents: 77
diff changeset
675 ioctl (fds, I_PUSH, "ldterm");
f4f6f44225d3 2002-12-10 Brian Masney <masneyb@gftp.org>
masneyb
parents: 77
diff changeset
676 ioctl (fds, I_PUSH, "ttcompat");
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
677 #endif
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
678
80
f4f6f44225d3 2002-12-10 Brian Masney <masneyb@gftp.org>
masneyb
parents: 77
diff changeset
679 #if !defined(HAVE_GRANTPT) && !defined (__sgi) && defined(TIOCSCTTY) && !defined(CIBAUD)
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
680
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
681 if (ioctl (fds, TIOCSCTTY, (char *) 0) < 0)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
682 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
683 close (fdm);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
684 return (-1);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
685 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
686
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
687 #endif
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
688
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
689 return (fds);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
690 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
691
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
692
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
693 int
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
694 tty_raw (int fd)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
695 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
696 struct termios buf;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
697
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
698 if (tcgetattr (fd, &buf) < 0)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
699 return (-1);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
700
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
701 buf.c_iflag |= IGNPAR;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
702 buf.c_iflag &= ~(ICRNL | ISTRIP | IXON | IGNCR | IXANY | IXOFF | INLCR);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
703 buf.c_lflag &= ~(ECHO | ICANON | ISIG | ECHOE | ECHOK | ECHONL);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
704 #ifdef IEXTEN
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
705 buf.c_lflag &= ~(IEXTEN);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
706 #endif
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
707
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
708 buf.c_oflag &= ~(OPOST);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
709 buf.c_cc[VMIN] = 1;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
710 buf.c_cc[VTIME] = 0;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
711
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
712 if (tcsetattr (fd, TCSADRAIN, &buf) < 0)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
713 return (-1);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
714 return (0);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
715 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
716
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
717
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
718 /* We have the caller send us a pointer to a string so we can write the port
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
719 into it. It makes it easier so we don't have to worry about freeing it
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
720 later on, the caller can just send us an auto variable, The string
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
721 should be at least 6 chars. I know this is messy... */
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
722
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
723 char **
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
724 make_ssh_exec_args (gftp_request * request, char *execname,
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
725 int use_sftp_subsys, char *portstring)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
726 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
727 char **args, *oldstr, *tempstr;
56
a12bcbc2fce4 2002-11-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
728 struct servent serv_struct;
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
729 int i, j;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
730
56
a12bcbc2fce4 2002-11-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
731 args = g_malloc (sizeof (char *) * (num_ssh_extra_params + 15));
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
732
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
733 args[0] = ssh_prog_name != NULL && *ssh_prog_name != '\0' ?
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
734 ssh_prog_name : "ssh";
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
735 i = 1;
56
a12bcbc2fce4 2002-11-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
736 tempstr = g_strdup (args[0]);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
737
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
738 if (ssh_extra_params_list != NULL)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
739 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
740 for (j=0; ssh_extra_params_list[j] != NULL; j++)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
741 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
742 oldstr = tempstr;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
743 args[i++] = ssh_extra_params_list[j];
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
744 tempstr = g_strconcat (oldstr, " ", ssh_extra_params_list[j], NULL);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
745 g_free (oldstr);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
746 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
747 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
748
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
749 oldstr = tempstr;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
750 tempstr = g_strconcat (oldstr, " -e none", NULL);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
751 g_free (oldstr);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
752 args[i++] = "-e";
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
753 args[i++] = "none";
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
754
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
755 if (request->username && *request->username != '\0')
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
756 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
757 oldstr = tempstr;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
758 tempstr = g_strconcat (oldstr, " -l ", request->username, NULL);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
759 g_free (oldstr);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
760 args[i++] = "-l";
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
761 args[i++] = request->username;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
762 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
763
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
764 if (request->port != 0)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
765 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
766 g_snprintf (portstring, 6, "%d", request->port);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
767 oldstr = tempstr;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
768 tempstr = g_strconcat (oldstr, " -p ", portstring, NULL);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
769 g_free (oldstr);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
770 args[i++] = "-p";
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
771 args[i++] = portstring;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
772 }
56
a12bcbc2fce4 2002-11-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
773 else
a12bcbc2fce4 2002-11-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
774 {
a12bcbc2fce4 2002-11-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
775 if (!r_getservbyname ("ssh", "tcp", &serv_struct, NULL))
a12bcbc2fce4 2002-11-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
776 request->port = 22;
a12bcbc2fce4 2002-11-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
777 else
a12bcbc2fce4 2002-11-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
778 request->port = ntohs (serv_struct.s_port);
a12bcbc2fce4 2002-11-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
779 }
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
780
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
781 if (use_sftp_subsys)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
782 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
783 oldstr = tempstr;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
784 tempstr = g_strconcat (oldstr, " ", request->hostname, " -s sftp", NULL);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
785 g_free (oldstr);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
786 args[i++] = request->hostname;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
787 args[i++] = "-s";
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
788 args[i++] = "sftp";
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
789 args[i] = NULL;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
790 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
791 else
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
792 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
793 oldstr = tempstr;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
794 tempstr = g_strconcat (oldstr, " ", request->hostname, " \"", execname,
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
795 "\"", NULL);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
796 g_free (oldstr);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
797 args[i++] = request->hostname;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
798 args[i++] = execname;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
799 args[i] = NULL;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
800 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
801
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
802 request->logging_function (gftp_logging_misc, request->user_data,
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
803 _("Running program %s\n"), tempstr);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
804 g_free (tempstr);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
805 return (args);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
806 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
807
61
42df9e4be8e0 2002-11-21 Brian Masney <masneyb@gftp.org>
masneyb
parents: 59
diff changeset
808 #define SSH_LOGIN_BUFSIZE 200
42df9e4be8e0 2002-11-21 Brian Masney <masneyb@gftp.org>
masneyb
parents: 59
diff changeset
809 #define SSH_ERROR_BADPASS -1
42df9e4be8e0 2002-11-21 Brian Masney <masneyb@gftp.org>
masneyb
parents: 59
diff changeset
810 #define SSH_ERROR_QUESTION -2
77
100a4b310c60 2002-12-4 Brian Masney <masneyb@gftp.org>
masneyb
parents: 67
diff changeset
811 #define SSH_WARNING -3
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
812
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
813 char *
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
814 ssh_start_login_sequence (gftp_request * request, int fd)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
815 {
65
4b5fec7711e9 2002-11-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
816 char *tempstr, *pwstr, *tmppos;
4b5fec7711e9 2002-11-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
817 size_t rem, len, diff, lastdiff, key_pos;
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
818 int wrotepw, ok;
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
819 ssize_t rd;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
820
61
42df9e4be8e0 2002-11-21 Brian Masney <masneyb@gftp.org>
masneyb
parents: 59
diff changeset
821 rem = len = SSH_LOGIN_BUFSIZE;
65
4b5fec7711e9 2002-11-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
822 tempstr = g_malloc0 (len + 1);
4b5fec7711e9 2002-11-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
823 key_pos = diff = lastdiff = 0;
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
824 wrotepw = 0;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
825 ok = 1;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
826
61
42df9e4be8e0 2002-11-21 Brian Masney <masneyb@gftp.org>
masneyb
parents: 59
diff changeset
827 if (gftp_set_sockblocking (request, fd, 1) == -1)
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
828 return (NULL);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
829
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
830 pwstr = g_strconcat (request->password, "\n", NULL);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
831
41
4bcfaf6307b5 2002-10-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 39
diff changeset
832 errno = 0;
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
833 while (1)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
834 {
61
42df9e4be8e0 2002-11-21 Brian Masney <masneyb@gftp.org>
masneyb
parents: 59
diff changeset
835 if ((rd = gftp_read (request, tempstr + diff, rem - 1, fd)) <= 0)
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
836 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
837 ok = 0;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
838 break;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
839 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
840 rem -= rd;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
841 diff += rd;
65
4b5fec7711e9 2002-11-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
842 tempstr[diff] = '\0';
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
843
61
42df9e4be8e0 2002-11-21 Brian Masney <masneyb@gftp.org>
masneyb
parents: 59
diff changeset
844 if (diff > 11 && strcmp (tempstr + diff - 10, "password: ") == 0)
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
845 {
61
42df9e4be8e0 2002-11-21 Brian Masney <masneyb@gftp.org>
masneyb
parents: 59
diff changeset
846 if (wrotepw)
42df9e4be8e0 2002-11-21 Brian Masney <masneyb@gftp.org>
masneyb
parents: 59
diff changeset
847 {
42df9e4be8e0 2002-11-21 Brian Masney <masneyb@gftp.org>
masneyb
parents: 59
diff changeset
848 ok = SSH_ERROR_BADPASS;
42df9e4be8e0 2002-11-21 Brian Masney <masneyb@gftp.org>
masneyb
parents: 59
diff changeset
849 break;
42df9e4be8e0 2002-11-21 Brian Masney <masneyb@gftp.org>
masneyb
parents: 59
diff changeset
850 }
77
100a4b310c60 2002-12-4 Brian Masney <masneyb@gftp.org>
masneyb
parents: 67
diff changeset
851
100a4b310c60 2002-12-4 Brian Masney <masneyb@gftp.org>
masneyb
parents: 67
diff changeset
852 if (strstr (tempstr, "WARNING") != NULL ||
100a4b310c60 2002-12-4 Brian Masney <masneyb@gftp.org>
masneyb
parents: 67
diff changeset
853 strstr (tempstr, _("WARNING")) != NULL)
100a4b310c60 2002-12-4 Brian Masney <masneyb@gftp.org>
masneyb
parents: 67
diff changeset
854 {
100a4b310c60 2002-12-4 Brian Masney <masneyb@gftp.org>
masneyb
parents: 67
diff changeset
855 ok = SSH_WARNING;
100a4b310c60 2002-12-4 Brian Masney <masneyb@gftp.org>
masneyb
parents: 67
diff changeset
856 break;
100a4b310c60 2002-12-4 Brian Masney <masneyb@gftp.org>
masneyb
parents: 67
diff changeset
857 }
61
42df9e4be8e0 2002-11-21 Brian Masney <masneyb@gftp.org>
masneyb
parents: 59
diff changeset
858
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
859 wrotepw = 1;
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
860 if (gftp_write (request, pwstr, strlen (pwstr), fd) < 0)
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
861 {
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
862 ok = 0;
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
863 break;
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
864 }
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
865 }
65
4b5fec7711e9 2002-11-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
866 else if (diff > 2 && strcmp (tempstr + diff - 2, ": ") == 0 &&
4b5fec7711e9 2002-11-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
867 ((tmppos = strstr (tempstr + key_pos, "Enter passphrase for RSA key")) != NULL ||
4b5fec7711e9 2002-11-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
868 ((tmppos = strstr (tempstr + key_pos, "Enter passphrase for key '")) != NULL)))
61
42df9e4be8e0 2002-11-21 Brian Masney <masneyb@gftp.org>
masneyb
parents: 59
diff changeset
869 {
65
4b5fec7711e9 2002-11-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
870 key_pos = diff;
61
42df9e4be8e0 2002-11-21 Brian Masney <masneyb@gftp.org>
masneyb
parents: 59
diff changeset
871 if (wrotepw)
42df9e4be8e0 2002-11-21 Brian Masney <masneyb@gftp.org>
masneyb
parents: 59
diff changeset
872 {
42df9e4be8e0 2002-11-21 Brian Masney <masneyb@gftp.org>
masneyb
parents: 59
diff changeset
873 ok = SSH_ERROR_BADPASS;
42df9e4be8e0 2002-11-21 Brian Masney <masneyb@gftp.org>
masneyb
parents: 59
diff changeset
874 break;
42df9e4be8e0 2002-11-21 Brian Masney <masneyb@gftp.org>
masneyb
parents: 59
diff changeset
875 }
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
876
77
100a4b310c60 2002-12-4 Brian Masney <masneyb@gftp.org>
masneyb
parents: 67
diff changeset
877 if (strstr (tempstr, "WARNING") != NULL ||
100a4b310c60 2002-12-4 Brian Masney <masneyb@gftp.org>
masneyb
parents: 67
diff changeset
878 strstr (tempstr, _("WARNING")) != NULL)
100a4b310c60 2002-12-4 Brian Masney <masneyb@gftp.org>
masneyb
parents: 67
diff changeset
879 {
100a4b310c60 2002-12-4 Brian Masney <masneyb@gftp.org>
masneyb
parents: 67
diff changeset
880 ok = SSH_WARNING;
100a4b310c60 2002-12-4 Brian Masney <masneyb@gftp.org>
masneyb
parents: 67
diff changeset
881 break;
100a4b310c60 2002-12-4 Brian Masney <masneyb@gftp.org>
masneyb
parents: 67
diff changeset
882 }
100a4b310c60 2002-12-4 Brian Masney <masneyb@gftp.org>
masneyb
parents: 67
diff changeset
883
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
884 wrotepw = 1;
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
885 if (gftp_write (request, pwstr, strlen (pwstr), fd) < 0)
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
886 {
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
887 ok = 0;
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
888 break;
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
889 }
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
890 }
65
4b5fec7711e9 2002-11-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
891 else if (diff > 10 && strcmp (tempstr + diff - 10, "(yes/no)? ") == 0)
61
42df9e4be8e0 2002-11-21 Brian Masney <masneyb@gftp.org>
masneyb
parents: 59
diff changeset
892 {
42df9e4be8e0 2002-11-21 Brian Masney <masneyb@gftp.org>
masneyb
parents: 59
diff changeset
893 ok = SSH_ERROR_QUESTION;
42df9e4be8e0 2002-11-21 Brian Masney <masneyb@gftp.org>
masneyb
parents: 59
diff changeset
894 break;
42df9e4be8e0 2002-11-21 Brian Masney <masneyb@gftp.org>
masneyb
parents: 59
diff changeset
895 }
42df9e4be8e0 2002-11-21 Brian Masney <masneyb@gftp.org>
masneyb
parents: 59
diff changeset
896 else if (diff >= 5 && strcmp (tempstr + diff - 5, "xsftp") == 0)
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
897 break;
65
4b5fec7711e9 2002-11-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
898 else if (rem <= 1)
4b5fec7711e9 2002-11-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
899 {
4b5fec7711e9 2002-11-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
900 request->logging_function (gftp_logging_recv, request->user_data,
4b5fec7711e9 2002-11-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
901 "%s", tempstr + lastdiff);
4b5fec7711e9 2002-11-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
902 len += SSH_LOGIN_BUFSIZE;
4b5fec7711e9 2002-11-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
903 rem += SSH_LOGIN_BUFSIZE;
4b5fec7711e9 2002-11-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
904 lastdiff = diff;
4b5fec7711e9 2002-11-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
905 tempstr = g_realloc (tempstr, len);
4b5fec7711e9 2002-11-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
906 continue;
4b5fec7711e9 2002-11-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
907 }
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
908 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
909
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
910 g_free (pwstr);
61
42df9e4be8e0 2002-11-21 Brian Masney <masneyb@gftp.org>
masneyb
parents: 59
diff changeset
911
42df9e4be8e0 2002-11-21 Brian Masney <masneyb@gftp.org>
masneyb
parents: 59
diff changeset
912 if (*(tempstr + lastdiff) != '\0')
42df9e4be8e0 2002-11-21 Brian Masney <masneyb@gftp.org>
masneyb
parents: 59
diff changeset
913 request->logging_function (gftp_logging_recv, request->user_data,
42df9e4be8e0 2002-11-21 Brian Masney <masneyb@gftp.org>
masneyb
parents: 59
diff changeset
914 "%s\n", tempstr + lastdiff);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
915
61
42df9e4be8e0 2002-11-21 Brian Masney <masneyb@gftp.org>
masneyb
parents: 59
diff changeset
916 if (ok <= 0)
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
917 {
61
42df9e4be8e0 2002-11-21 Brian Masney <masneyb@gftp.org>
masneyb
parents: 59
diff changeset
918 if (ok == SSH_ERROR_BADPASS)
42df9e4be8e0 2002-11-21 Brian Masney <masneyb@gftp.org>
masneyb
parents: 59
diff changeset
919 request->logging_function (gftp_logging_error, request->user_data,
42df9e4be8e0 2002-11-21 Brian Masney <masneyb@gftp.org>
masneyb
parents: 59
diff changeset
920 _("Error: An incorrect password was entered\n"));
42df9e4be8e0 2002-11-21 Brian Masney <masneyb@gftp.org>
masneyb
parents: 59
diff changeset
921 else if (ok == SSH_ERROR_QUESTION)
42df9e4be8e0 2002-11-21 Brian Masney <masneyb@gftp.org>
masneyb
parents: 59
diff changeset
922 request->logging_function (gftp_logging_error, request->user_data,
42df9e4be8e0 2002-11-21 Brian Masney <masneyb@gftp.org>
masneyb
parents: 59
diff changeset
923 _("Please connect to this host with the command line SSH utility and answer this question appropriately.\n"));
77
100a4b310c60 2002-12-4 Brian Masney <masneyb@gftp.org>
masneyb
parents: 67
diff changeset
924 else if (ok == SSH_WARNING)
100a4b310c60 2002-12-4 Brian Masney <masneyb@gftp.org>
masneyb
parents: 67
diff changeset
925 request->logging_function (gftp_logging_error, request->user_data,
100a4b310c60 2002-12-4 Brian Masney <masneyb@gftp.org>
masneyb
parents: 67
diff changeset
926 _("Please correct the above warning to connect to this host.\n"));
61
42df9e4be8e0 2002-11-21 Brian Masney <masneyb@gftp.org>
masneyb
parents: 59
diff changeset
927
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
928 g_free (tempstr);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
929 return (NULL);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
930 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
931
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
932 return (tempstr);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
933 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
934
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
935
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
936 #ifdef G_HAVE_GINT64
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
937
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
938 gint64
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
939 hton64 (gint64 val)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
940 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
941 gint64 num;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
942 char *pos;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
943
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
944 num = 0;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
945 pos = (char *) &num;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
946 pos[0] = (val >> 56) & 0xff;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
947 pos[1] = (val >> 48) & 0xff;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
948 pos[2] = (val >> 40) & 0xff;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
949 pos[3] = (val >> 32) & 0xff;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
950 pos[4] = (val >> 24) & 0xff;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
951 pos[5] = (val >> 16) & 0xff;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
952 pos[6] = (val >> 8) & 0xff;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
953 pos[7] = val & 0xff;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
954 return (num);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
955 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
956
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
957 #endif
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
958
16
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
959
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
960 static gint
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
961 gftp_file_sort_function_as (gconstpointer a, gconstpointer b)
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
962 {
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
963 const gftp_file * f1, * f2;
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
964
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
965 f1 = a;
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
966 f2 = b;
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
967 return (strcmp (f1->file, f2->file));
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
968 }
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
969
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
970
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
971 static gint
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
972 gftp_file_sort_function_ds (gconstpointer a, gconstpointer b)
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
973 {
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
974 const gftp_file * f1, * f2;
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
975 gint ret;
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
976
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
977 f1 = a;
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
978 f2 = b;
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
979 ret = strcmp (f1->file, f2->file);
84
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 80
diff changeset
980 return (ret * -1);
16
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
981 }
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
982
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
983
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
984 static gint
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
985 gftp_user_sort_function_as (gconstpointer a, gconstpointer b)
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
986 {
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
987 const gftp_file * f1, * f2;
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
988
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
989 f1 = a;
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
990 f2 = b;
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
991 return (strcmp (f1->user, f2->user));
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
992 }
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
993
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
994
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
995 static gint
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
996 gftp_user_sort_function_ds (gconstpointer a, gconstpointer b)
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
997 {
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
998 const gftp_file * f1, * f2;
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
999 gint ret;
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
1000
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
1001 f1 = a;
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
1002 f2 = b;
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
1003 ret = strcmp (f1->user, f2->user);
84
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 80
diff changeset
1004 return (ret * -1);
16
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
1005 }
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
1006
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
1007
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
1008 static gint
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
1009 gftp_group_sort_function_as (gconstpointer a, gconstpointer b)
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
1010 {
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
1011 const gftp_file * f1, * f2;
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
1012
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
1013 f1 = a;
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
1014 f2 = b;
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
1015 return (strcmp (f1->group, f2->group));
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
1016 }
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
1017
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
1018
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
1019 static gint
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
1020 gftp_group_sort_function_ds (gconstpointer a, gconstpointer b)
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
1021 {
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
1022 const gftp_file * f1, * f2;
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
1023 gint ret;
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
1024
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
1025 f1 = a;
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
1026 f2 = b;
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
1027 ret = strcmp (f1->group, f2->group);
84
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 80
diff changeset
1028 return (ret * -1);
16
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
1029 }
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
1030
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
1031
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
1032 static gint
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
1033 gftp_attribs_sort_function_as (gconstpointer a, gconstpointer b)
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
1034 {
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
1035 const gftp_file * f1, * f2;
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
1036
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
1037 f1 = a;
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
1038 f2 = b;
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
1039 return (strcmp (f1->attribs, f2->attribs));
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
1040 }
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
1041
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
1042
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
1043 static gint
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
1044 gftp_attribs_sort_function_ds (gconstpointer a, gconstpointer b)
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
1045 {
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
1046 const gftp_file * f1, * f2;
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
1047 gint ret;
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
1048
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
1049 f1 = a;
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
1050 f2 = b;
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
1051 ret = strcmp (f1->attribs, f2->attribs);
84
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 80
diff changeset
1052 return (ret * -1);
16
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
1053 }
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
1054
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
1055
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
1056 static gint
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
1057 gftp_size_sort_function_as (gconstpointer a, gconstpointer b)
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
1058 {
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
1059 const gftp_file * f1, * f2;
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
1060
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
1061 f1 = a;
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
1062 f2 = b;
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
1063 if (f1->size < f2->size)
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
1064 return (-1);
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
1065 else if (f1->size == f2->size)
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
1066 return (0);
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
1067 else
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
1068 return (1);
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
1069 }
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
1070
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
1071
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
1072 static gint
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
1073 gftp_size_sort_function_ds (gconstpointer a, gconstpointer b)
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
1074 {
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
1075 const gftp_file * f1, * f2;
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
1076
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
1077 f1 = a;
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
1078 f2 = b;
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
1079 if (f1->size < f2->size)
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
1080 return (1);
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
1081 else if (f1->size == f2->size)
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
1082 return (0);
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
1083 else
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
1084 return (-1);
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
1085 }
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
1086
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
1087
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
1088 static gint
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
1089 gftp_datetime_sort_function_as (gconstpointer a, gconstpointer b)
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
1090 {
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
1091 const gftp_file * f1, * f2;
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
1092
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
1093 f1 = a;
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
1094 f2 = b;
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
1095 if (f1->datetime < f2->datetime)
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
1096 return (-1);
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
1097 else if (f1->datetime == f2->datetime)
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
1098 return (0);
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
1099 else
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
1100 return (1);
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
1101 }
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
1102
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
1103
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
1104 static gint
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
1105 gftp_datetime_sort_function_ds (gconstpointer a, gconstpointer b)
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
1106 {
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
1107 const gftp_file * f1, * f2;
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
1108
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
1109 f1 = a;
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
1110 f2 = b;
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
1111 if (f1->datetime < f2->datetime)
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
1112 return (1);
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
1113 else if (f1->datetime == f2->datetime)
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
1114 return (0);
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
1115 else
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
1116 return (-1);
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
1117 }
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
1118
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
1119
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
1120 GList *
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
1121 gftp_sort_filelist (GList * filelist, int column, int asds)
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
1122 {
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
1123 GList * files, * dirs, * dotdot, * tempitem, * insitem;
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
1124 GCompareFunc sortfunc;
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
1125 gftp_file * tempfle;
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
1126
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
1127 files = dirs = dotdot = NULL;
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
1128
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
1129 if (column == GFTP_SORT_COL_FILE)
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
1130 sortfunc = asds ? gftp_file_sort_function_as : gftp_file_sort_function_ds;
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
1131 else if (column == GFTP_SORT_COL_SIZE)
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
1132 sortfunc = asds ? gftp_size_sort_function_as : gftp_size_sort_function_ds;
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
1133 else if (column == GFTP_SORT_COL_USER)
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
1134 sortfunc = asds ? gftp_user_sort_function_as : gftp_user_sort_function_ds;
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
1135 else if (column == GFTP_SORT_COL_GROUP)
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
1136 sortfunc = asds ?
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
1137 gftp_group_sort_function_as : gftp_group_sort_function_ds;
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
1138 else if (column == GFTP_SORT_COL_DATETIME)
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
1139 sortfunc = asds ?
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
1140 gftp_datetime_sort_function_as : gftp_datetime_sort_function_ds; else /* GFTP_SORT_COL_ATTRIBS */
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
1141 sortfunc = asds ?
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
1142 gftp_attribs_sort_function_as : gftp_attribs_sort_function_ds;
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
1143
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
1144 for (tempitem = filelist; tempitem != NULL; )
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
1145 {
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
1146 tempfle = tempitem->data;
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
1147 insitem = tempitem;
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
1148 tempitem = tempitem->next;
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
1149 insitem->next = NULL;
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
1150
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
1151 if (dotdot == NULL && strcmp (tempfle->file, "..") == 0)
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
1152 dotdot = insitem;
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
1153 else if (sort_dirs_first && tempfle->isdir)
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
1154 {
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
1155 insitem->next = dirs;
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
1156 dirs = insitem;
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
1157 }
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
1158 else
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
1159 {
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
1160 insitem->next = files;
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
1161 files = insitem;
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
1162 }
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
1163 }
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
1164
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
1165 if (dirs != NULL)
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
1166 dirs = g_list_sort (dirs, sortfunc);
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
1167 if (files != NULL)
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
1168 files = g_list_sort (files, sortfunc);
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
1169
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
1170 filelist = dotdot;
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
1171
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
1172 if (filelist == NULL)
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
1173 filelist = dirs;
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
1174 else
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
1175 filelist = g_list_concat (filelist, dirs);
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
1176
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
1177 if (filelist == NULL)
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
1178 filelist = files;
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
1179 else
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
1180 filelist = g_list_concat (filelist, files);
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
1181
39
474d562c7268 2002-10-15 Brian Masney <masneyb@gftp.org>
masneyb
parents: 33
diff changeset
1182 /* I haven't check this, but I'm pretty sure some older versions of glib
474d562c7268 2002-10-15 Brian Masney <masneyb@gftp.org>
masneyb
parents: 33
diff changeset
1183 had a bug that the prev pointer wasn't being sent to NULL */
474d562c7268 2002-10-15 Brian Masney <masneyb@gftp.org>
masneyb
parents: 33
diff changeset
1184 filelist->prev = NULL;
16
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
1185 return (filelist);
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
1186 }
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
1187