annotate lib/misc.c @ 119:71c8f9c09566

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