annotate lib/misc.c @ 122:76e2b58a9440

2003-4-5 Brian Masney <masneyb@gftp.org> * lib/config_file.c lib/options.h lib/gftp.h lib/rfc959.c lib/rfc2068.c lib/ssh.c - added new internal configuration interface. Rather than having a global variable for each option, I have a global hash table (gftp_global_options_htable) that I can look up option names by name using gftp_lookup_global_option(). I also an options hash associated with a request structure, so I will be able to call gftp_lookup_request_option(). I will be able to override options with bookmarks or while transfers are in progress very easily now. Also, all options no longer have to appear in config_file.c, the per protocol options can appear inside their own file * lib/gftp.h lib/bookmarks.c lib/local.c lib/rfc959.c lib/rfc2068.c - remove set_data_type and protocol name from struct gftp_request * lib/rfc959.c - renamed all firewall_* variables to ftp_proxy_* in the config file * lib/gftp.h lib/protocols.c lib/rfc959.c - renamed all GFTP_TYPE_* vars to GFTP_DIRTYPE_* * lib/gftp.h - removed ascii field and renamed the node pointer to user_data in struct gftp_file. In gftp_request, removed any setting that is now stored in the global/local hash tables. Added register_module() pointer that will be called whenever the protocol is first loaded into gftp * lib/rfc959.c src/text/gftp-text.c - moved the ascii/binary translation to rfc959.c. Also, moved any instance of automatically setting the data type to rfc959.c as well. * lib/misc.c lib/sshv2.c - moved all ssh functions from misc.c to sshv2.c. I had these origionally in misc.c because I used to have 2 different SSH protocols * lib/protocols.c src/text/gftp-text.c - added gftp_calc_kbs() to protocols.c. This no longer needs to be in the different ports * src/text/gftp-text.c - read/write options based on new configuration interface * Use new configuration interface in all source files * Updated copyright dates on all source files * Note: GTK+ port is completely broken at the moment. I'll upload those changes whenever I get them done
author masneyb
date Sat, 05 Apr 2003 16:30:45 +0000
parents 3b573c8ef706
children 65048c959029
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 */
122
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 102
diff changeset
3 /* Copyright (C) 1998-2003 Brian Masney <masneyb@gftp.org> */
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
4 /* */
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
5 /* This program is free software; you can redistribute it and/or modify */
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
6 /* it under the terms of the GNU General Public License as published by */
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
7 /* the Free Software Foundation; either version 2 of the License, or */
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
8 /* (at your option) any later version. */
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
9 /* */
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
10 /* This program is distributed in the hope that it will be useful, */
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
11 /* but WITHOUT ANY WARRANTY; without even the implied warranty of */
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
12 /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
13 /* GNU General Public License for more details. */
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
14 /* */
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
15 /* You should have received a copy of the GNU General Public License */
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
16 /* along with this program; if not, write to the Free Software */
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
17 /* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111 USA */
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
18 /*****************************************************************************/
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
19
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 {
122
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 102
diff changeset
350 printf ("%s\n", gftp_version);
1
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->fromreq != NULL)
67
aa971a4bb16f 2002-11-27 Brian Masney <masneyb@gftp.org>
masneyb
parents: 66
diff changeset
534 gftp_request_destroy (tdata->fromreq, 1);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
535 if (tdata->toreq != NULL)
67
aa971a4bb16f 2002-11-27 Brian Masney <masneyb@gftp.org>
masneyb
parents: 66
diff changeset
536 gftp_request_destroy (tdata->toreq, 1);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
537 free_file_list (tdata->files);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
538 g_free (tdata);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
539 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
540
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
541
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
542 gftp_request *
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
543 copy_request (gftp_request * req)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
544 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
545 gftp_request * newreq;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
546
66
cd3e457cbc85 2002-11-26 Brian Masney <masneyb@gftp.org>
masneyb
parents: 65
diff changeset
547 newreq = gftp_request_new ();
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
548
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
549 if (req->hostname)
56
a12bcbc2fce4 2002-11-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
550 newreq->hostname = g_strdup (req->hostname);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
551 if (req->username)
56
a12bcbc2fce4 2002-11-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
552 newreq->username = g_strdup (req->username);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
553 if (req->password)
56
a12bcbc2fce4 2002-11-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
554 newreq->password = g_strdup (req->password);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
555 if (req->account)
56
a12bcbc2fce4 2002-11-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
556 newreq->account = g_strdup (req->account);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
557 if (req->directory)
56
a12bcbc2fce4 2002-11-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
558 newreq->directory = g_strdup (req->directory);
66
cd3e457cbc85 2002-11-26 Brian Masney <masneyb@gftp.org>
masneyb
parents: 65
diff changeset
559 newreq->port = req->port;
cd3e457cbc85 2002-11-26 Brian Masney <masneyb@gftp.org>
masneyb
parents: 65
diff changeset
560 newreq->use_proxy = req->use_proxy;
cd3e457cbc85 2002-11-26 Brian Masney <masneyb@gftp.org>
masneyb
parents: 65
diff changeset
561 newreq->logging_function = req->logging_function;
122
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 102
diff changeset
562 newreq->local_options = NULL; /* FIXME */
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
563
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
564 req->init (newreq);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
565
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
566 return (newreq);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
567 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
568
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
569
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
570 int
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
571 ptym_open (char *pts_name)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
572 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
573 int fd;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
574
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
575 #ifdef __sgi
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
576 char *tempstr;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
577
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
578 if ((tempstr = _getpty (&fd, O_RDWR, 0600, 0)) == NULL)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
579 return (-1);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
580
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
581 strcpy (pts_name, tempstr);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
582 return (fd);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
583
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
584 #else /* !__sgi */
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
585
80
f4f6f44225d3 2002-12-10 Brian Masney <masneyb@gftp.org>
masneyb
parents: 77
diff changeset
586 #ifdef HAVE_GRANTPT
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
587
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
588 char *tempstr;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
589
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
590 strcpy (pts_name, "/dev/ptmx");
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
591 if ((fd = open (pts_name, O_RDWR)) < 0)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
592 return (-1);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
593
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
594 if (grantpt (fd) < 0)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
595 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
596 close (fd);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
597 return (-1);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
598 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
599
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
600 if (unlockpt (fd) < 0)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
601 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
602 close (fd);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
603 return (-1);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
604 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
605
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
606 if ((tempstr = ptsname (fd)) == NULL)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
607 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
608 close (fd);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
609 return (-1);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
610 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
611
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
612 strcpy (pts_name, tempstr);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
613 return (fd);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
614
80
f4f6f44225d3 2002-12-10 Brian Masney <masneyb@gftp.org>
masneyb
parents: 77
diff changeset
615 #else /* !GRANTPT */
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
616
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
617 char *pos1, *pos2;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
618
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
619 strcpy (pts_name, "/dev/ptyXY");
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
620 for (pos1 = "pqrstuvwxyzPQRST"; *pos1 != '\0'; pos1++)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
621 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
622 pts_name[8] = *pos1;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
623 for (pos2 = "0123456789abcdef"; *pos2 != '\0'; pos2++)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
624 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
625 pts_name[9] = *pos2;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
626 if ((fd = open (pts_name, O_RDWR)) < 0)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
627 continue;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
628 pts_name[5] = 't';
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
629 return (fd);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
630 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
631 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
632 return (-1);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
633
87
6df043359b41 2003-1-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 84
diff changeset
634 #endif /* GRANTPT */
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
635
87
6df043359b41 2003-1-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 84
diff changeset
636 #endif /* __sgi */
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
637
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
638 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
639
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
640
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
641 int
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
642 ptys_open (int fdm, char *pts_name)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
643 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
644 int fds;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
645
80
f4f6f44225d3 2002-12-10 Brian Masney <masneyb@gftp.org>
masneyb
parents: 77
diff changeset
646 #if !defined (HAVE_GRANTPT) && !defined (__sgi)
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
647
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
648 chmod (pts_name, S_IRUSR | S_IWUSR);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
649 chown (pts_name, getuid (), -1);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
650
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
651 #endif
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
652
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
653 if ((fds = open (pts_name, O_RDWR)) < 0)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
654 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
655 close (fdm);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
656 return (-1);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
657 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
658
80
f4f6f44225d3 2002-12-10 Brian Masney <masneyb@gftp.org>
masneyb
parents: 77
diff changeset
659 #ifdef HAVE_GRANTPT
f4f6f44225d3 2002-12-10 Brian Masney <masneyb@gftp.org>
masneyb
parents: 77
diff changeset
660 /* I intentionally ignore these errors */
f4f6f44225d3 2002-12-10 Brian Masney <masneyb@gftp.org>
masneyb
parents: 77
diff changeset
661 ioctl (fds, I_PUSH, "ptem");
f4f6f44225d3 2002-12-10 Brian Masney <masneyb@gftp.org>
masneyb
parents: 77
diff changeset
662 ioctl (fds, I_PUSH, "ldterm");
f4f6f44225d3 2002-12-10 Brian Masney <masneyb@gftp.org>
masneyb
parents: 77
diff changeset
663 ioctl (fds, I_PUSH, "ttcompat");
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
664 #endif
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
665
80
f4f6f44225d3 2002-12-10 Brian Masney <masneyb@gftp.org>
masneyb
parents: 77
diff changeset
666 #if !defined(HAVE_GRANTPT) && !defined (__sgi) && defined(TIOCSCTTY) && !defined(CIBAUD)
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
667
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
668 if (ioctl (fds, TIOCSCTTY, (char *) 0) < 0)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
669 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
670 close (fdm);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
671 return (-1);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
672 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
673
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
674 #endif
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
675
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
676 return (fds);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
677 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
678
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
679
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
680 int
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
681 tty_raw (int fd)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
682 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
683 struct termios buf;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
684
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
685 if (tcgetattr (fd, &buf) < 0)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
686 return (-1);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
687
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
688 buf.c_iflag |= IGNPAR;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
689 buf.c_iflag &= ~(ICRNL | ISTRIP | IXON | IGNCR | IXANY | IXOFF | INLCR);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
690 buf.c_lflag &= ~(ECHO | ICANON | ISIG | ECHOE | ECHOK | ECHONL);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
691 #ifdef IEXTEN
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
692 buf.c_lflag &= ~(IEXTEN);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
693 #endif
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
694
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
695 buf.c_oflag &= ~(OPOST);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
696 buf.c_cc[VMIN] = 1;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
697 buf.c_cc[VTIME] = 0;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
698
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
699 if (tcsetattr (fd, TCSADRAIN, &buf) < 0)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
700 return (-1);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
701 return (0);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
702 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
703
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
704
16
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
705 static gint
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
706 gftp_file_sort_function_as (gconstpointer a, gconstpointer b)
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
707 {
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
708 const gftp_file * f1, * f2;
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
709
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
710 f1 = a;
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
711 f2 = b;
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
712 return (strcmp (f1->file, f2->file));
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
713 }
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
714
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
715
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
716 static gint
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
717 gftp_file_sort_function_ds (gconstpointer a, gconstpointer b)
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
718 {
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
719 const gftp_file * f1, * f2;
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
720 gint ret;
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
721
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
722 f1 = a;
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
723 f2 = b;
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
724 ret = strcmp (f1->file, f2->file);
84
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 80
diff changeset
725 return (ret * -1);
16
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
726 }
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
727
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
728
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
729 static gint
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
730 gftp_user_sort_function_as (gconstpointer a, gconstpointer b)
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
731 {
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
732 const gftp_file * f1, * f2;
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
733
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
734 f1 = a;
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
735 f2 = b;
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
736 return (strcmp (f1->user, f2->user));
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
737 }
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
738
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
739
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
740 static gint
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
741 gftp_user_sort_function_ds (gconstpointer a, gconstpointer b)
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
742 {
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
743 const gftp_file * f1, * f2;
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
744 gint ret;
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
745
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
746 f1 = a;
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
747 f2 = b;
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
748 ret = strcmp (f1->user, f2->user);
84
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 80
diff changeset
749 return (ret * -1);
16
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
750 }
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
751
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
752
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
753 static gint
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
754 gftp_group_sort_function_as (gconstpointer a, gconstpointer b)
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
755 {
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
756 const gftp_file * f1, * f2;
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
757
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
758 f1 = a;
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
759 f2 = b;
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
760 return (strcmp (f1->group, f2->group));
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
761 }
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
762
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
763
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
764 static gint
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
765 gftp_group_sort_function_ds (gconstpointer a, gconstpointer b)
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
766 {
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
767 const gftp_file * f1, * f2;
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
768 gint ret;
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
769
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
770 f1 = a;
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
771 f2 = b;
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
772 ret = strcmp (f1->group, f2->group);
84
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 80
diff changeset
773 return (ret * -1);
16
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
774 }
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
775
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
776
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
777 static gint
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
778 gftp_attribs_sort_function_as (gconstpointer a, gconstpointer b)
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
779 {
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
780 const gftp_file * f1, * f2;
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
781
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
782 f1 = a;
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
783 f2 = b;
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
784 return (strcmp (f1->attribs, f2->attribs));
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
785 }
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
786
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
787
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
788 static gint
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
789 gftp_attribs_sort_function_ds (gconstpointer a, gconstpointer b)
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
790 {
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
791 const gftp_file * f1, * f2;
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
792 gint ret;
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
793
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
794 f1 = a;
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
795 f2 = b;
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
796 ret = strcmp (f1->attribs, f2->attribs);
84
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 80
diff changeset
797 return (ret * -1);
16
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
798 }
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
799
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
800
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
801 static gint
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
802 gftp_size_sort_function_as (gconstpointer a, gconstpointer b)
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
803 {
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
804 const gftp_file * f1, * f2;
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
805
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
806 f1 = a;
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
807 f2 = b;
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
808 if (f1->size < f2->size)
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
809 return (-1);
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
810 else if (f1->size == f2->size)
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
811 return (0);
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
812 else
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
813 return (1);
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
814 }
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
815
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
816
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
817 static gint
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
818 gftp_size_sort_function_ds (gconstpointer a, gconstpointer b)
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
819 {
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
820 const gftp_file * f1, * f2;
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
821
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
822 f1 = a;
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
823 f2 = b;
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
824 if (f1->size < f2->size)
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
825 return (1);
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
826 else if (f1->size == f2->size)
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
827 return (0);
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
828 else
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
829 return (-1);
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
830 }
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
831
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
832
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
833 static gint
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
834 gftp_datetime_sort_function_as (gconstpointer a, gconstpointer b)
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
835 {
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
836 const gftp_file * f1, * f2;
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
837
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
838 f1 = a;
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
839 f2 = b;
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
840 if (f1->datetime < f2->datetime)
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
841 return (-1);
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
842 else if (f1->datetime == f2->datetime)
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
843 return (0);
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
844 else
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
845 return (1);
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
846 }
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
847
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
848
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
849 static gint
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
850 gftp_datetime_sort_function_ds (gconstpointer a, gconstpointer b)
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
851 {
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
852 const gftp_file * f1, * f2;
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
853
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
854 f1 = a;
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
855 f2 = b;
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
856 if (f1->datetime < f2->datetime)
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
857 return (1);
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
858 else if (f1->datetime == f2->datetime)
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
859 return (0);
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
860 else
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
861 return (-1);
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
862 }
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
863
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
864
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
865 GList *
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
866 gftp_sort_filelist (GList * filelist, int column, int asds)
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
867 {
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
868 GList * files, * dirs, * dotdot, * tempitem, * insitem;
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
869 GCompareFunc sortfunc;
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
870 gftp_file * tempfle;
122
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 102
diff changeset
871 int sort_dirs_first;
16
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
872
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
873 files = dirs = dotdot = NULL;
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
874
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
875 if (column == GFTP_SORT_COL_FILE)
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
876 sortfunc = asds ? gftp_file_sort_function_as : gftp_file_sort_function_ds;
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
877 else if (column == GFTP_SORT_COL_SIZE)
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
878 sortfunc = asds ? gftp_size_sort_function_as : gftp_size_sort_function_ds;
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
879 else if (column == GFTP_SORT_COL_USER)
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
880 sortfunc = asds ? gftp_user_sort_function_as : gftp_user_sort_function_ds;
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
881 else if (column == GFTP_SORT_COL_GROUP)
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
882 sortfunc = asds ?
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
883 gftp_group_sort_function_as : gftp_group_sort_function_ds;
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
884 else if (column == GFTP_SORT_COL_DATETIME)
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
885 sortfunc = asds ?
122
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 102
diff changeset
886 gftp_datetime_sort_function_as : gftp_datetime_sort_function_ds;
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 102
diff changeset
887 else if (column == GFTP_SORT_COL_ATTRIBS)
16
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
888 sortfunc = asds ?
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
889 gftp_attribs_sort_function_as : gftp_attribs_sort_function_ds;
122
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 102
diff changeset
890 else /* Don't sort */
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 102
diff changeset
891 return (filelist);
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 102
diff changeset
892
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 102
diff changeset
893 sort_dirs_first = 1;
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 102
diff changeset
894 gftp_lookup_global_option ("sort_dirs_first", &sort_dirs_first);
16
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
895
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
896 for (tempitem = filelist; tempitem != NULL; )
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
897 {
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
898 tempfle = tempitem->data;
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
899 insitem = tempitem;
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
900 tempitem = tempitem->next;
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
901 insitem->next = NULL;
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
902
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
903 if (dotdot == NULL && strcmp (tempfle->file, "..") == 0)
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
904 dotdot = insitem;
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
905 else if (sort_dirs_first && tempfle->isdir)
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
906 {
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
907 insitem->next = dirs;
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
908 dirs = insitem;
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
909 }
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
910 else
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
911 {
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
912 insitem->next = files;
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
913 files = insitem;
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
914 }
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
915 }
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
916
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
917 if (dirs != NULL)
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
918 dirs = g_list_sort (dirs, sortfunc);
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
919 if (files != NULL)
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
920 files = g_list_sort (files, sortfunc);
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
921
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
922 filelist = dotdot;
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
923
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
924 if (filelist == NULL)
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
925 filelist = dirs;
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
926 else
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
927 filelist = g_list_concat (filelist, dirs);
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
928
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
929 if (filelist == NULL)
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
930 filelist = files;
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
931 else
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
932 filelist = g_list_concat (filelist, files);
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
933
39
474d562c7268 2002-10-15 Brian Masney <masneyb@gftp.org>
masneyb
parents: 33
diff changeset
934 /* 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
935 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
936 filelist->prev = NULL;
16
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
937 return (filelist);
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
938 }
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
939