annotate lib/misc.c @ 201:0098dae654a5

2003-6-25 Brian Masney <masneyb@gftp.org> * configure.in - added mk to ALL_LINGUAS * lib/gftp.h - added several macros for dmalloc * lib/misc.c src/text/gftp-text.c src/gtk/gftp-gtk.c - added gftp_shutdown() to misc.c. This will write out the configuration file, clear the cache, and if dmalloc is enabled, free the memory that was allocated on startup * lib/config_file.c lib/gftp.h lib/misc.c lib/options.h - added gftp_configuration_changed parameter * lib/config_file.c lib/misc.c lib/protocols.c - added gftp_config_free_options() * lib/config_file.c src/gtk/bookmarks.c - added gftp_bookmarks() which is derived mostly from bm_close_dialog() * lib/rfc959.c - added rfc959_request_destroy(). Free the getline buffers in this function * src/gtk/misc-gtk.c (gftp_item_factory_translate) - remove double g_strdup() call * lib/config_file.c lib/gftp.h src/gtk/misc-gtk.c - moved get_xpm_path() to GTK+ port. No longer call it startup when reading the config file
author masneyb
date Thu, 26 Jun 2003 01:04:12 +0000
parents 75eebb3b0592
children 95e669973a84
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;
124
65048c959029 2003-4-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 122
diff changeset
127 str = g_strdup (src);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
128
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
129 if (*str == '~')
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
130 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
131 if (*(str + 1) == '/' || *(str + 1) == '\0')
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
132 pw = getpwuid (geteuid ());
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
133 else
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
134 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
135 if ((pos = strchr (str, '/')) != NULL)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
136 *pos = '\0';
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
137
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
138 pw = getpwnam (str + 1);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
139
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
140 if (pos != NULL)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
141 *pos = '/';
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
142 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
143 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
144
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
145 endpos = str;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
146 newstr = NULL;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
147 while ((pos = strchr (endpos, '/')) != NULL)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
148 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
149 pos++;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
150 while (*pos == '/')
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
151 pos++;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
152 if ((endpos = strchr (pos, '/')) == NULL)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
153 endpos = pos + strlen (pos);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
154 tempchar = *endpos;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
155 *endpos = '\0';
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
156 if (strcmp (pos, "..") == 0)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
157 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
158 *(pos - 1) = '\0';
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
159 if (newstr != NULL && (prevpos = strrchr (newstr, '/')) != NULL)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
160 *prevpos = '\0';
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
161 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
162 else if (strcmp (pos, ".") != 0)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
163 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
164 if (newstr == NULL)
56
a12bcbc2fce4 2002-11-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
165 newstr = g_strdup (pos - 1);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
166 else
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
167 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
168 tempstr = g_strconcat (newstr, pos - 1, NULL);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
169 g_free (newstr);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
170 newstr = tempstr;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
171 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
172 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
173 *endpos = tempchar;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
174 if (*endpos == '\0')
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
175 break;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
176 endpos = pos + 1;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
177 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
178
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
179 if (newstr == NULL || *newstr == '\0')
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
180 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
181 if (newstr != NULL)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
182 g_free (newstr);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
183 newstr = g_malloc0 (2);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
184 *newstr = '/';
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
185 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
186
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
187 g_free (str);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
188
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
189 if (pw != NULL)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
190 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
191 if ((pos = strchr (newstr, '/')) == NULL)
124
65048c959029 2003-4-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 122
diff changeset
192 str = g_strdup (pw->pw_dir);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
193 else
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
194 str = g_strconcat (pw->pw_dir, pos, NULL);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
195
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
196 g_free (newstr);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
197 newstr = str;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
198 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
199
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
200 return (newstr);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
201 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
202
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
203
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
204 void
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
205 remove_double_slashes (char *string)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
206 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
207 char *newpos, *oldpos;
87
6df043359b41 2003-1-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 84
diff changeset
208 size_t len;
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
209
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
210 oldpos = newpos = string;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
211 while (*oldpos != '\0')
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
212 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
213 *newpos++ = *oldpos++;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
214 if (*oldpos == '\0')
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
215 break;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
216 while (*(newpos - 1) == '/' && *(oldpos) == '/')
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
217 oldpos++;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
218 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
219 *newpos = '\0';
87
6df043359b41 2003-1-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 84
diff changeset
220
6df043359b41 2003-1-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 84
diff changeset
221 len = strlen (string);
6df043359b41 2003-1-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 84
diff changeset
222 if (string[len - 1] == '/')
6df043359b41 2003-1-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 84
diff changeset
223 string[len - 1] = '\0';
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
224 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
225
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
226
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
227 void
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
228 make_nonnull (char **str)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
229 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
230 if (*str == NULL)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
231 *str = g_malloc0 (1);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
232 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
233
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
234
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
235 int
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
236 copyfile (char *source, char *dest)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
237 {
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
238 int srcfd, destfd;
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
239 char buf[8192];
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
240 ssize_t n;
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
241
182
33b394ebba68 2003-6-15 Brian Masney <masneyb@gftp.org>
masneyb
parents: 173
diff changeset
242 if ((srcfd = gftp_fd_open (NULL, source, O_RDONLY, 0)) == -1)
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
243 {
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
244 printf (_("Error: Cannot open local file %s: %s\n"),
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
245 source, g_strerror (errno));
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
246 exit (1);
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
247 }
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
248
182
33b394ebba68 2003-6-15 Brian Masney <masneyb@gftp.org>
masneyb
parents: 173
diff changeset
249 if ((destfd = gftp_fd_open (NULL, dest, O_WRONLY | O_CREAT, S_IRUSR | S_IWUSR)) == -1)
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
250 {
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
251 printf (_("Error: Cannot open local file %s: %s\n"),
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
252 dest, g_strerror (errno));
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
253 close (srcfd);
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
254 exit (1);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
255 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
256
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
257 while ((n = read (srcfd, buf, sizeof (buf))) > 0)
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
258 {
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
259 if (write (destfd, buf, n) == -1)
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
260 {
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
261 printf (_("Error: Could not write to socket: %s\n"),
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
262 g_strerror (errno));
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
263 exit (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 }
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
266
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
267 if (n == -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 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
270 exit (1);
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
271 }
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
272
87
6df043359b41 2003-1-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 84
diff changeset
273 if (close (srcfd) == -1)
6df043359b41 2003-1-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 84
diff changeset
274 {
6df043359b41 2003-1-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 84
diff changeset
275 printf (_("Error closing file descriptor: %s\n"), g_strerror (errno));
6df043359b41 2003-1-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 84
diff changeset
276 exit (1);
6df043359b41 2003-1-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 84
diff changeset
277 }
6df043359b41 2003-1-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 84
diff changeset
278
6df043359b41 2003-1-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 84
diff changeset
279 if (close (destfd) == -1)
6df043359b41 2003-1-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 84
diff changeset
280 {
6df043359b41 2003-1-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 84
diff changeset
281 printf (_("Error closing file descriptor: %s\n"), g_strerror (errno));
6df043359b41 2003-1-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 84
diff changeset
282 exit (1);
6df043359b41 2003-1-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 84
diff changeset
283 }
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
284
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
285 return (1);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
286 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
287
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
288
87
6df043359b41 2003-1-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 84
diff changeset
289 /* FIXME - is there a replacement for this */
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
290 int
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
291 gftp_match_filespec (char *filename, char *filespec)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
292 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
293 char *filepos, *wcpos, *pos, *newpos, search_str[20];
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
294 size_t len, curlen;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
295
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
296 if (filename == NULL || *filename == '\0' ||
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
297 filespec == NULL || *filespec == '\0')
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
298 return(1);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
299
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
300 filepos = filename;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
301 wcpos = filespec;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
302 while(1)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
303 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
304 if (*wcpos == '\0')
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
305 return (1);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
306 else if (*filepos == '\0')
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
307 return(0);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
308 else if(*wcpos == '?')
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
309 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
310 wcpos++;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
311 filepos++;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
312 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
313 else if(*wcpos == '*' && *(wcpos+1) == '\0')
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
314 return(1);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
315 else if(*wcpos == '*')
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
316 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
317 len = sizeof (search_str);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
318 for (pos = wcpos + 1, newpos = search_str, curlen = 0;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
319 *pos != '*' && *pos != '?' && *pos != '\0' && curlen < len;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
320 curlen++, *newpos++ = *pos++);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
321 *newpos = '\0';
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
322
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
323 if ((filepos = strstr (filepos, search_str)) == NULL)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
324 return(0);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
325 wcpos += curlen + 1;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
326 filepos += curlen;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
327 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
328 else if(*wcpos++ != *filepos++)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
329 return(0);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
330 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
331 return (1);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
332 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
333
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
334
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
335 int
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
336 gftp_parse_command_line (int *argc, char ***argv)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
337 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
338 if (*argc > 1)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
339 {
87
6df043359b41 2003-1-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 84
diff changeset
340 if (strcmp (argv[0][1], "--help") == 0 ||
6df043359b41 2003-1-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 84
diff changeset
341 strcmp (argv[0][1], "-h") == 0)
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
342 gftp_usage ();
87
6df043359b41 2003-1-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 84
diff changeset
343 else if (strcmp (argv[0][1], "--version") == 0 ||
6df043359b41 2003-1-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 84
diff changeset
344 strcmp (argv[0][1], "-v") == 0)
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
345 {
122
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 102
diff changeset
346 printf ("%s\n", gftp_version);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
347 exit (0);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
348 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
349 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
350 return (0);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
351 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
352
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
353
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
354 void
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
355 gftp_usage (void)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
356 {
162
12a043d992a1 2003-5-22 Brian Masney <masneyb@gftp.org>
masneyb
parents: 151
diff changeset
357 printf (_("usage: gftp [[protocol://][user[:pass]@]site[:port][/directory]]\n"));
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
358 exit (0);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
359 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
360
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
361
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
362 gint
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
363 string_hash_compare (gconstpointer path1, gconstpointer path2)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
364 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
365 return (strcmp ((char *) path1, (char *) path2) == 0);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
366 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
367
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
368
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
369 guint
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
370 string_hash_function (gconstpointer key)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
371 {
59
618423504fe0 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 58
diff changeset
372 guint ret;
618423504fe0 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 58
diff changeset
373 int i;
618423504fe0 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 58
diff changeset
374
618423504fe0 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 58
diff changeset
375 ret = 0;
87
6df043359b41 2003-1-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 84
diff changeset
376 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
377 ret += ((char *) key)[i];
618423504fe0 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 58
diff changeset
378
618423504fe0 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 58
diff changeset
379 return (ret);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
380 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
381
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
382
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
383 void
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
384 free_file_list (GList * filelist)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
385 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
386 gftp_file * tempfle;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
387 GList * templist;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
388
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
389 templist = filelist;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
390 while (templist != NULL)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
391 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
392 tempfle = templist->data;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
393 free_fdata (tempfle);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
394 templist = templist->next;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
395 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
396 g_list_free (filelist);
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 void
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
401 free_fdata (gftp_file * fle)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
402 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
403 if (fle->file)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
404 g_free (fle->file);
184
65eb40fb4f03 2003-6-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 182
diff changeset
405 if (fle->utf8_file)
65eb40fb4f03 2003-6-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 182
diff changeset
406 g_free (fle->utf8_file);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
407 if (fle->user)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
408 g_free (fle->user);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
409 if (fle->group)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
410 g_free (fle->group);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
411 if (fle->attribs)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
412 g_free (fle->attribs);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
413 if (fle->destfile)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
414 g_free (fle->destfile);
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
415 if (fle->fd > 0)
102
3b573c8ef706 2003-2-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 87
diff changeset
416 close (fle->fd);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
417 g_free (fle);
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 gftp_file *
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
422 copy_fdata (gftp_file * fle)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
423 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
424 gftp_file * newfle;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
425
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
426 newfle = g_malloc0 (sizeof (*newfle));
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
427 memcpy (newfle, fle, sizeof (*newfle));
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
428
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
429 if (fle->file)
87
6df043359b41 2003-1-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 84
diff changeset
430 newfle->file = g_strdup (fle->file);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
431
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
432 if (fle->user)
87
6df043359b41 2003-1-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 84
diff changeset
433 newfle->user = g_strdup (fle->user);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
434
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
435 if (fle->group)
87
6df043359b41 2003-1-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 84
diff changeset
436 newfle->group = g_strdup (fle->group);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
437
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
438 if (fle->attribs)
87
6df043359b41 2003-1-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 84
diff changeset
439 newfle->attribs = g_strdup (fle->attribs);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
440
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
441 if (fle->destfile)
87
6df043359b41 2003-1-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 84
diff changeset
442 newfle->destfile = g_strdup (fle->destfile);
6df043359b41 2003-1-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 84
diff changeset
443
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
444 return (newfle);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
445 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
446
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
447
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
448 int
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
449 compare_request (gftp_request * request1, gftp_request * request2,
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
450 int compare_dirs)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
451 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
452 char *strarr[3][2];
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
453 int i, ret;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
454
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
455 ret = 1;
87
6df043359b41 2003-1-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 84
diff changeset
456 if (request1->protonum == request2->protonum &&
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
457 request1->port == request2->port)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
458 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
459 strarr[0][0] = request1->hostname;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
460 strarr[0][1] = request2->hostname;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
461 strarr[1][0] = request1->username;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
462 strarr[1][1] = request2->username;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
463 if (compare_dirs)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
464 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
465 strarr[2][0] = request1->directory;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
466 strarr[2][1] = request2->directory;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
467 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
468 else
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
469 strarr[2][0] = strarr[2][1] = "";
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
470
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
471 for (i = 0; i < 3; i++)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
472 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
473 if ((strarr[i][0] && !strarr[i][1]) ||
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
474 (!strarr[i][0] && strarr[i][1]))
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
475 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
476 ret = 0;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
477 break;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
478 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
479
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
480 if (strarr[i][0] && strarr[i][1] &&
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
481 strcmp (strarr[i][0], strarr[i][1]) != 0)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
482 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
483 ret = 0;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
484 break;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
485 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
486 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
487 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
488 else
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
489 ret = 0;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
490 return (ret);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
491 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
492
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
493
129
fe0b21c006f6 2003-4-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 125
diff changeset
494 gftp_transfer *
fe0b21c006f6 2003-4-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 125
diff changeset
495 gftp_tdata_new (void)
fe0b21c006f6 2003-4-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 125
diff changeset
496 {
fe0b21c006f6 2003-4-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 125
diff changeset
497 gftp_transfer * tdata;
fe0b21c006f6 2003-4-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 125
diff changeset
498
fe0b21c006f6 2003-4-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 125
diff changeset
499 tdata = g_malloc0 (sizeof (*tdata));
168
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 162
diff changeset
500 g_static_mutex_init (&tdata->statmutex);
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 162
diff changeset
501 g_static_mutex_init (&tdata->structmutex);
129
fe0b21c006f6 2003-4-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 125
diff changeset
502 return (tdata);
fe0b21c006f6 2003-4-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 125
diff changeset
503 }
fe0b21c006f6 2003-4-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 125
diff changeset
504
fe0b21c006f6 2003-4-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 125
diff changeset
505
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
506 void
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
507 free_tdata (gftp_transfer * tdata)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
508 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
509 if (tdata->fromreq != NULL)
67
aa971a4bb16f 2002-11-27 Brian Masney <masneyb@gftp.org>
masneyb
parents: 66
diff changeset
510 gftp_request_destroy (tdata->fromreq, 1);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
511 if (tdata->toreq != NULL)
67
aa971a4bb16f 2002-11-27 Brian Masney <masneyb@gftp.org>
masneyb
parents: 66
diff changeset
512 gftp_request_destroy (tdata->toreq, 1);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
513 free_file_list (tdata->files);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
514 g_free (tdata);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
515 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
516
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
517
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
518 gftp_request *
151
2f15b3000dbc 2003-4-27 Brian Masney <masneyb@gftp.org>
masneyb
parents: 146
diff changeset
519 copy_request (gftp_request * req, int copy_local_options)
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
520 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
521 gftp_request * newreq;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
522
66
cd3e457cbc85 2002-11-26 Brian Masney <masneyb@gftp.org>
masneyb
parents: 65
diff changeset
523 newreq = gftp_request_new ();
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
524
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
525 if (req->hostname)
56
a12bcbc2fce4 2002-11-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
526 newreq->hostname = g_strdup (req->hostname);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
527 if (req->username)
56
a12bcbc2fce4 2002-11-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
528 newreq->username = g_strdup (req->username);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
529 if (req->password)
56
a12bcbc2fce4 2002-11-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
530 newreq->password = g_strdup (req->password);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
531 if (req->account)
56
a12bcbc2fce4 2002-11-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
532 newreq->account = g_strdup (req->account);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
533 if (req->directory)
56
a12bcbc2fce4 2002-11-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
534 newreq->directory = g_strdup (req->directory);
66
cd3e457cbc85 2002-11-26 Brian Masney <masneyb@gftp.org>
masneyb
parents: 65
diff changeset
535 newreq->port = req->port;
cd3e457cbc85 2002-11-26 Brian Masney <masneyb@gftp.org>
masneyb
parents: 65
diff changeset
536 newreq->use_proxy = req->use_proxy;
cd3e457cbc85 2002-11-26 Brian Masney <masneyb@gftp.org>
masneyb
parents: 65
diff changeset
537 newreq->logging_function = req->logging_function;
151
2f15b3000dbc 2003-4-27 Brian Masney <masneyb@gftp.org>
masneyb
parents: 146
diff changeset
538 newreq->free_hostp = 0;
2f15b3000dbc 2003-4-27 Brian Masney <masneyb@gftp.org>
masneyb
parents: 146
diff changeset
539 newreq->hostp = req->hostp;
2f15b3000dbc 2003-4-27 Brian Masney <masneyb@gftp.org>
masneyb
parents: 146
diff changeset
540
2f15b3000dbc 2003-4-27 Brian Masney <masneyb@gftp.org>
masneyb
parents: 146
diff changeset
541 if (copy_local_options)
199
75eebb3b0592 2003-6-24 Brian Masney <masneyb@gftp.org>
masneyb
parents: 184
diff changeset
542 gftp_copy_local_options (&newreq->local_options_vars,
75eebb3b0592 2003-6-24 Brian Masney <masneyb@gftp.org>
masneyb
parents: 184
diff changeset
543 &newreq->local_options_hash,
75eebb3b0592 2003-6-24 Brian Masney <masneyb@gftp.org>
masneyb
parents: 184
diff changeset
544 req->local_options_vars,
75eebb3b0592 2003-6-24 Brian Masney <masneyb@gftp.org>
masneyb
parents: 184
diff changeset
545 req->num_local_options_vars);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
546
173
4c288d05b26a 2003-6-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 168
diff changeset
547 if (req->init (newreq) < 0)
4c288d05b26a 2003-6-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 168
diff changeset
548 {
4c288d05b26a 2003-6-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 168
diff changeset
549 gftp_request_destroy (newreq, 1);
4c288d05b26a 2003-6-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 168
diff changeset
550 return (NULL);
4c288d05b26a 2003-6-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 168
diff changeset
551 }
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
552
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
553 return (newreq);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
554 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
555
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
556
16
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
557 static gint
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
558 gftp_file_sort_function_as (gconstpointer a, gconstpointer b)
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
559 {
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
560 const gftp_file * f1, * f2;
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
561
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
562 f1 = a;
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
563 f2 = b;
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
564 return (strcmp (f1->file, f2->file));
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
565 }
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
566
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
567
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
568 static gint
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
569 gftp_file_sort_function_ds (gconstpointer a, gconstpointer b)
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
570 {
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
571 const gftp_file * f1, * f2;
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
572 gint ret;
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
573
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
574 f1 = a;
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
575 f2 = b;
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
576 ret = strcmp (f1->file, f2->file);
84
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 80
diff changeset
577 return (ret * -1);
16
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
578 }
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
579
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
580
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
581 static gint
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
582 gftp_user_sort_function_as (gconstpointer a, gconstpointer b)
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
583 {
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
584 const gftp_file * f1, * f2;
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
585
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
586 f1 = a;
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
587 f2 = b;
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
588 return (strcmp (f1->user, f2->user));
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
589 }
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
590
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
591
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
592 static gint
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
593 gftp_user_sort_function_ds (gconstpointer a, gconstpointer b)
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
594 {
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
595 const gftp_file * f1, * f2;
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
596 gint ret;
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
597
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
598 f1 = a;
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
599 f2 = b;
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
600 ret = strcmp (f1->user, f2->user);
84
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 80
diff changeset
601 return (ret * -1);
16
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
602 }
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
603
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
604
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
605 static gint
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
606 gftp_group_sort_function_as (gconstpointer a, gconstpointer b)
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
607 {
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
608 const gftp_file * f1, * f2;
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
609
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
610 f1 = a;
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
611 f2 = b;
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
612 return (strcmp (f1->group, f2->group));
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
613 }
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
614
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
615
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
616 static gint
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
617 gftp_group_sort_function_ds (gconstpointer a, gconstpointer b)
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
618 {
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
619 const gftp_file * f1, * f2;
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
620 gint ret;
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
621
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
622 f1 = a;
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
623 f2 = b;
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
624 ret = strcmp (f1->group, f2->group);
84
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 80
diff changeset
625 return (ret * -1);
16
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
626 }
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
627
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
628
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
629 static gint
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
630 gftp_attribs_sort_function_as (gconstpointer a, gconstpointer b)
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
631 {
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
632 const gftp_file * f1, * f2;
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
633
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
634 f1 = a;
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
635 f2 = b;
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
636 return (strcmp (f1->attribs, f2->attribs));
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
637 }
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
638
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
639
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
640 static gint
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
641 gftp_attribs_sort_function_ds (gconstpointer a, gconstpointer b)
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
642 {
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
643 const gftp_file * f1, * f2;
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
644 gint ret;
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
645
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
646 f1 = a;
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
647 f2 = b;
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
648 ret = strcmp (f1->attribs, f2->attribs);
84
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 80
diff changeset
649 return (ret * -1);
16
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
650 }
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
651
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
652
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
653 static gint
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
654 gftp_size_sort_function_as (gconstpointer a, gconstpointer b)
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
655 {
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
656 const gftp_file * f1, * f2;
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
657
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
658 f1 = a;
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
659 f2 = b;
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
660 if (f1->size < f2->size)
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
661 return (-1);
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
662 else if (f1->size == f2->size)
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
663 return (0);
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
664 else
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
665 return (1);
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
666 }
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
667
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
668
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
669 static gint
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
670 gftp_size_sort_function_ds (gconstpointer a, gconstpointer b)
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
671 {
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
672 const gftp_file * f1, * f2;
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
673
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
674 f1 = a;
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
675 f2 = b;
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
676 if (f1->size < f2->size)
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
677 return (1);
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
678 else if (f1->size == f2->size)
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
679 return (0);
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
680 else
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
681 return (-1);
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
682 }
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
683
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
684
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
685 static gint
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
686 gftp_datetime_sort_function_as (gconstpointer a, gconstpointer b)
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
687 {
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
688 const gftp_file * f1, * f2;
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
689
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
690 f1 = a;
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
691 f2 = b;
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
692 if (f1->datetime < f2->datetime)
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
693 return (-1);
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
694 else if (f1->datetime == f2->datetime)
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
695 return (0);
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
696 else
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
697 return (1);
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
698 }
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
699
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
700
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
701 static gint
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
702 gftp_datetime_sort_function_ds (gconstpointer a, gconstpointer b)
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
703 {
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
704 const gftp_file * f1, * f2;
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
705
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
706 f1 = a;
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
707 f2 = b;
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
708 if (f1->datetime < f2->datetime)
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
709 return (1);
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
710 else if (f1->datetime == f2->datetime)
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
711 return (0);
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
712 else
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
713 return (-1);
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
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
717 GList *
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
718 gftp_sort_filelist (GList * filelist, int column, int asds)
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
719 {
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
720 GList * files, * dirs, * dotdot, * tempitem, * insitem;
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
721 GCompareFunc sortfunc;
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
722 gftp_file * tempfle;
122
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 102
diff changeset
723 int sort_dirs_first;
16
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
724
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
725 files = dirs = dotdot = NULL;
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
726
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
727 if (column == GFTP_SORT_COL_FILE)
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
728 sortfunc = asds ? gftp_file_sort_function_as : gftp_file_sort_function_ds;
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
729 else if (column == GFTP_SORT_COL_SIZE)
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
730 sortfunc = asds ? gftp_size_sort_function_as : gftp_size_sort_function_ds;
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
731 else if (column == GFTP_SORT_COL_USER)
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
732 sortfunc = asds ? gftp_user_sort_function_as : gftp_user_sort_function_ds;
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
733 else if (column == GFTP_SORT_COL_GROUP)
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
734 sortfunc = asds ?
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
735 gftp_group_sort_function_as : gftp_group_sort_function_ds;
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
736 else if (column == GFTP_SORT_COL_DATETIME)
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
737 sortfunc = asds ?
122
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 102
diff changeset
738 gftp_datetime_sort_function_as : gftp_datetime_sort_function_ds;
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 102
diff changeset
739 else if (column == GFTP_SORT_COL_ATTRIBS)
16
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
740 sortfunc = asds ?
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
741 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
742 else /* Don't sort */
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 102
diff changeset
743 return (filelist);
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 102
diff changeset
744
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 102
diff changeset
745 sort_dirs_first = 1;
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 102
diff changeset
746 gftp_lookup_global_option ("sort_dirs_first", &sort_dirs_first);
16
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
747
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
748 for (tempitem = filelist; tempitem != NULL; )
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
749 {
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
750 tempfle = tempitem->data;
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
751 insitem = tempitem;
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
752 tempitem = tempitem->next;
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
753 insitem->next = NULL;
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
754
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
755 if (dotdot == NULL && strcmp (tempfle->file, "..") == 0)
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
756 dotdot = insitem;
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
757 else if (sort_dirs_first && tempfle->isdir)
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
758 {
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
759 insitem->next = dirs;
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
760 dirs = insitem;
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
761 }
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
762 else
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
763 {
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
764 insitem->next = files;
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
765 files = insitem;
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
766 }
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
767 }
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
768
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
769 if (dirs != NULL)
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
770 dirs = g_list_sort (dirs, sortfunc);
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
771 if (files != NULL)
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
772 files = g_list_sort (files, sortfunc);
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
773
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
774 filelist = dotdot;
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
775
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
776 if (filelist == NULL)
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
777 filelist = dirs;
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
778 else
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
779 filelist = g_list_concat (filelist, dirs);
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
780
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
781 if (filelist == NULL)
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
782 filelist = files;
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
783 else
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
784 filelist = g_list_concat (filelist, files);
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
785
39
474d562c7268 2002-10-15 Brian Masney <masneyb@gftp.org>
masneyb
parents: 33
diff changeset
786 /* 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
787 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
788 filelist->prev = NULL;
16
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
789 return (filelist);
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
790 }
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
791
125
b875de05c22d 2003-4-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
792
b875de05c22d 2003-4-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
793 mode_t
b875de05c22d 2003-4-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
794 gftp_parse_attribs (char *attribs)
b875de05c22d 2003-4-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
795 {
b875de05c22d 2003-4-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
796 mode_t mode;
b875de05c22d 2003-4-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
797 int cur;
b875de05c22d 2003-4-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
798
b875de05c22d 2003-4-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
799 cur = 0;
b875de05c22d 2003-4-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
800 if (attribs[1] == 'r')
b875de05c22d 2003-4-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
801 cur += 4;
b875de05c22d 2003-4-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
802 if (attribs[2] == 'w')
b875de05c22d 2003-4-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
803 cur += 2;
b875de05c22d 2003-4-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
804 if (attribs[3] == 'x' ||
b875de05c22d 2003-4-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
805 attribs[3] == 's')
b875de05c22d 2003-4-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
806 cur += 1;
b875de05c22d 2003-4-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
807 mode = cur;
b875de05c22d 2003-4-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
808
b875de05c22d 2003-4-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
809 cur = 0;
b875de05c22d 2003-4-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
810 if (attribs[4] == 'r')
b875de05c22d 2003-4-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
811 cur += 4;
b875de05c22d 2003-4-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
812 if (attribs[5] == 'w')
b875de05c22d 2003-4-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
813 cur += 2;
b875de05c22d 2003-4-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
814 if (attribs[6] == 'x' ||
b875de05c22d 2003-4-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
815 attribs[6] == 's')
b875de05c22d 2003-4-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
816 cur += 1;
b875de05c22d 2003-4-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
817 mode = (mode * 10) + cur;
b875de05c22d 2003-4-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
818
b875de05c22d 2003-4-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
819 cur = 0;
b875de05c22d 2003-4-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
820 if (attribs[7] == 'r')
b875de05c22d 2003-4-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
821 cur += 4;
b875de05c22d 2003-4-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
822 if (attribs[8] == 'w')
b875de05c22d 2003-4-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
823 cur += 2;
b875de05c22d 2003-4-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
824 if (attribs[9] == 'x' ||
b875de05c22d 2003-4-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
825 attribs[9] == 's')
b875de05c22d 2003-4-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
826 cur += 1;
b875de05c22d 2003-4-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
827 mode = (mode * 10) + cur;
b875de05c22d 2003-4-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
828
b875de05c22d 2003-4-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
829 return (mode);
b875de05c22d 2003-4-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
830 }
b875de05c22d 2003-4-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
831
b875de05c22d 2003-4-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
832
131
c77f85763e28 2003-4-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 129
diff changeset
833 char *
c77f85763e28 2003-4-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 129
diff changeset
834 gftp_gen_ls_string (gftp_file * fle, char *file_prefixstr, char *file_suffixstr)
c77f85763e28 2003-4-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 129
diff changeset
835 {
c77f85763e28 2003-4-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 129
diff changeset
836 char *tempstr1, *tempstr2, *ret, tstr[50];
c77f85763e28 2003-4-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 129
diff changeset
837 struct tm *lt;
c77f85763e28 2003-4-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 129
diff changeset
838 time_t t;
c77f85763e28 2003-4-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 129
diff changeset
839
c77f85763e28 2003-4-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 129
diff changeset
840 lt = localtime (&fle->datetime);
c77f85763e28 2003-4-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 129
diff changeset
841
c77f85763e28 2003-4-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 129
diff changeset
842 tempstr1 = g_strdup_printf ("%10s %8s %8s", fle->attribs, fle->user,
c77f85763e28 2003-4-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 129
diff changeset
843 fle->group);
c77f85763e28 2003-4-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 129
diff changeset
844
c77f85763e28 2003-4-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 129
diff changeset
845 if (fle->attribs && (*fle->attribs == 'b' || *fle->attribs == 'c'))
c77f85763e28 2003-4-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 129
diff changeset
846 tempstr2 = g_strdup_printf ("%d, %d", major (fle->size), minor (fle->size));
c77f85763e28 2003-4-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 129
diff changeset
847 else
c77f85763e28 2003-4-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 129
diff changeset
848 {
c77f85763e28 2003-4-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 129
diff changeset
849 #if defined (_LARGEFILE_SOURCE)
c77f85763e28 2003-4-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 129
diff changeset
850 tempstr2 = g_strdup_printf ("%11lld", fle->size);
c77f85763e28 2003-4-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 129
diff changeset
851 #else
c77f85763e28 2003-4-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 129
diff changeset
852 tempstr2 = g_strdup_printf ("%11ld", fle->size);
c77f85763e28 2003-4-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 129
diff changeset
853 #endif
c77f85763e28 2003-4-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 129
diff changeset
854 }
c77f85763e28 2003-4-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 129
diff changeset
855
c77f85763e28 2003-4-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 129
diff changeset
856 time (&t);
c77f85763e28 2003-4-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 129
diff changeset
857
c77f85763e28 2003-4-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 129
diff changeset
858 if (fle->datetime > t || t - 3600*24*90 > fle->datetime)
c77f85763e28 2003-4-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 129
diff changeset
859 strftime (tstr, sizeof (tstr), "%b %d %Y", lt);
c77f85763e28 2003-4-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 129
diff changeset
860 else
c77f85763e28 2003-4-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 129
diff changeset
861 strftime (tstr, sizeof (tstr), "%b %d %H:%M", lt);
c77f85763e28 2003-4-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 129
diff changeset
862
c77f85763e28 2003-4-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 129
diff changeset
863 if (file_prefixstr == NULL)
c77f85763e28 2003-4-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 129
diff changeset
864 file_prefixstr = "";
c77f85763e28 2003-4-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 129
diff changeset
865 if (file_suffixstr == NULL)
c77f85763e28 2003-4-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 129
diff changeset
866 file_suffixstr = "";
c77f85763e28 2003-4-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 129
diff changeset
867
c77f85763e28 2003-4-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 129
diff changeset
868 ret = g_strdup_printf ("%s %s %s %s%s%s", tempstr1, tempstr2, tstr,
184
65eb40fb4f03 2003-6-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 182
diff changeset
869 file_prefixstr,
65eb40fb4f03 2003-6-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 182
diff changeset
870 fle->utf8_file != NULL ? fle->utf8_file : fle->file,
65eb40fb4f03 2003-6-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 182
diff changeset
871 file_suffixstr);
131
c77f85763e28 2003-4-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 129
diff changeset
872
c77f85763e28 2003-4-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 129
diff changeset
873 g_free (tempstr1);
c77f85763e28 2003-4-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 129
diff changeset
874 g_free (tempstr2);
c77f85763e28 2003-4-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 129
diff changeset
875
c77f85763e28 2003-4-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 129
diff changeset
876 return (ret);
c77f85763e28 2003-4-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 129
diff changeset
877 }
c77f85763e28 2003-4-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 129
diff changeset
878
c77f85763e28 2003-4-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 129
diff changeset
879
125
b875de05c22d 2003-4-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
880 #if !defined (HAVE_GETADDRINFO) || !defined (HAVE_GAI_STRERROR)
b875de05c22d 2003-4-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
881
b875de05c22d 2003-4-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
882 struct hostent *
b875de05c22d 2003-4-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
883 r_gethostbyname (const char *name, struct hostent *result_buf, int *h_errnop)
b875de05c22d 2003-4-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
884 {
b875de05c22d 2003-4-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
885 static GStaticMutex hostfunclock = G_STATIC_MUTEX_INIT;
b875de05c22d 2003-4-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
886 struct hostent *hent;
b875de05c22d 2003-4-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
887
b875de05c22d 2003-4-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
888 if (g_thread_supported ())
b875de05c22d 2003-4-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
889 g_static_mutex_lock (&hostfunclock);
b875de05c22d 2003-4-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
890
b875de05c22d 2003-4-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
891 if ((hent = gethostbyname (name)) == NULL)
b875de05c22d 2003-4-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
892 {
b875de05c22d 2003-4-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
893 if (h_errnop)
b875de05c22d 2003-4-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
894 *h_errnop = h_errno;
b875de05c22d 2003-4-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
895 }
b875de05c22d 2003-4-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
896 else
b875de05c22d 2003-4-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
897 {
b875de05c22d 2003-4-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
898 *result_buf = *hent;
b875de05c22d 2003-4-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
899 hent = result_buf;
b875de05c22d 2003-4-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
900 }
b875de05c22d 2003-4-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
901
b875de05c22d 2003-4-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
902 if (g_thread_supported ())
b875de05c22d 2003-4-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
903 g_static_mutex_unlock (&hostfunclock);
b875de05c22d 2003-4-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
904
b875de05c22d 2003-4-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
905 return (hent);
b875de05c22d 2003-4-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
906 }
b875de05c22d 2003-4-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
907
b875de05c22d 2003-4-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
908 #endif /* !HAVE_GETADDRINFO */
b875de05c22d 2003-4-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
909
b875de05c22d 2003-4-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
910 struct servent *
b875de05c22d 2003-4-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
911 r_getservbyname (const char *name, const char *proto,
b875de05c22d 2003-4-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
912 struct servent *result_buf, int *h_errnop)
b875de05c22d 2003-4-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
913 {
b875de05c22d 2003-4-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
914 static GStaticMutex servfunclock = G_STATIC_MUTEX_INIT;
b875de05c22d 2003-4-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
915 struct servent *sent;
b875de05c22d 2003-4-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
916
b875de05c22d 2003-4-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
917 if (g_thread_supported ())
b875de05c22d 2003-4-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
918 g_static_mutex_lock (&servfunclock);
b875de05c22d 2003-4-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
919
b875de05c22d 2003-4-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
920 if ((sent = getservbyname (name, proto)) == NULL)
b875de05c22d 2003-4-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
921 {
b875de05c22d 2003-4-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
922 if (h_errnop)
b875de05c22d 2003-4-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
923 *h_errnop = h_errno;
b875de05c22d 2003-4-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
924 }
b875de05c22d 2003-4-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
925 else
b875de05c22d 2003-4-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
926 {
b875de05c22d 2003-4-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
927 *result_buf = *sent;
b875de05c22d 2003-4-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
928 sent = result_buf;
b875de05c22d 2003-4-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
929 }
b875de05c22d 2003-4-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
930
b875de05c22d 2003-4-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
931 if (g_thread_supported ())
b875de05c22d 2003-4-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
932 g_static_mutex_unlock (&servfunclock);
b875de05c22d 2003-4-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
933 return (sent);
b875de05c22d 2003-4-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
934 }
b875de05c22d 2003-4-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
935
168
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 162
diff changeset
936
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 162
diff changeset
937 char *
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 162
diff changeset
938 base64_encode (char *str)
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 162
diff changeset
939 {
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 162
diff changeset
940
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 162
diff changeset
941 /* The standard to Base64 encoding can be found in RFC2045 */
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 162
diff changeset
942
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 162
diff changeset
943 char *newstr, *newpos, *fillpos, *pos;
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 162
diff changeset
944 unsigned char table[64], encode[3];
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 162
diff changeset
945 int i, num;
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 162
diff changeset
946
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 162
diff changeset
947 for (i = 0; i < 26; i++)
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 162
diff changeset
948 {
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 162
diff changeset
949 table[i] = 'A' + i;
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 162
diff changeset
950 table[i + 26] = 'a' + i;
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 162
diff changeset
951 }
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 162
diff changeset
952
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 162
diff changeset
953 for (i = 0; i < 10; i++)
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 162
diff changeset
954 table[i + 52] = '0' + i;
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 162
diff changeset
955
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 162
diff changeset
956 table[62] = '+';
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 162
diff changeset
957 table[63] = '-';
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 162
diff changeset
958
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 162
diff changeset
959 num = strlen (str) / 3;
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 162
diff changeset
960 if (strlen (str) % 3 > 0)
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 162
diff changeset
961 num++;
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 162
diff changeset
962 newstr = g_malloc (num * 4 + 1);
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 162
diff changeset
963 newstr[num * 4] = '\0';
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 162
diff changeset
964 newpos = newstr;
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 162
diff changeset
965
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 162
diff changeset
966 pos = str;
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 162
diff changeset
967 while (*pos != '\0')
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 162
diff changeset
968 {
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 162
diff changeset
969 memset (encode, 0, sizeof (encode));
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 162
diff changeset
970 for (i = 0; i < 3 && *pos != '\0'; i++)
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 162
diff changeset
971 encode[i] = *pos++;
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 162
diff changeset
972
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 162
diff changeset
973 fillpos = newpos;
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 162
diff changeset
974 *newpos++ = table[encode[0] >> 2];
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 162
diff changeset
975 *newpos++ = table[(encode[0] & 3) << 4 | encode[1] >> 4];
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 162
diff changeset
976 *newpos++ = table[(encode[1] & 0xF) << 2 | encode[2] >> 6];
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 162
diff changeset
977 *newpos++ = table[encode[2] & 0x3F];
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 162
diff changeset
978 while (i < 3)
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 162
diff changeset
979 fillpos[++i] = '=';
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 162
diff changeset
980 }
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 162
diff changeset
981 return (newstr);
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 162
diff changeset
982 }
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 162
diff changeset
983
199
75eebb3b0592 2003-6-24 Brian Masney <masneyb@gftp.org>
masneyb
parents: 184
diff changeset
984
75eebb3b0592 2003-6-24 Brian Masney <masneyb@gftp.org>
masneyb
parents: 184
diff changeset
985 void
75eebb3b0592 2003-6-24 Brian Masney <masneyb@gftp.org>
masneyb
parents: 184
diff changeset
986 gftp_free_bookmark (gftp_bookmarks_var * entry)
75eebb3b0592 2003-6-24 Brian Masney <masneyb@gftp.org>
masneyb
parents: 184
diff changeset
987 {
75eebb3b0592 2003-6-24 Brian Masney <masneyb@gftp.org>
masneyb
parents: 184
diff changeset
988 if (entry->hostname)
75eebb3b0592 2003-6-24 Brian Masney <masneyb@gftp.org>
masneyb
parents: 184
diff changeset
989 g_free (entry->hostname);
75eebb3b0592 2003-6-24 Brian Masney <masneyb@gftp.org>
masneyb
parents: 184
diff changeset
990 if (entry->remote_dir)
75eebb3b0592 2003-6-24 Brian Masney <masneyb@gftp.org>
masneyb
parents: 184
diff changeset
991 g_free (entry->remote_dir);
75eebb3b0592 2003-6-24 Brian Masney <masneyb@gftp.org>
masneyb
parents: 184
diff changeset
992 if (entry->local_dir)
75eebb3b0592 2003-6-24 Brian Masney <masneyb@gftp.org>
masneyb
parents: 184
diff changeset
993 g_free (entry->local_dir);
75eebb3b0592 2003-6-24 Brian Masney <masneyb@gftp.org>
masneyb
parents: 184
diff changeset
994 if (entry->user)
75eebb3b0592 2003-6-24 Brian Masney <masneyb@gftp.org>
masneyb
parents: 184
diff changeset
995 g_free (entry->user);
75eebb3b0592 2003-6-24 Brian Masney <masneyb@gftp.org>
masneyb
parents: 184
diff changeset
996 if (entry->pass)
75eebb3b0592 2003-6-24 Brian Masney <masneyb@gftp.org>
masneyb
parents: 184
diff changeset
997 g_free (entry->pass);
75eebb3b0592 2003-6-24 Brian Masney <masneyb@gftp.org>
masneyb
parents: 184
diff changeset
998 if (entry->acct)
75eebb3b0592 2003-6-24 Brian Masney <masneyb@gftp.org>
masneyb
parents: 184
diff changeset
999 g_free (entry->acct);
75eebb3b0592 2003-6-24 Brian Masney <masneyb@gftp.org>
masneyb
parents: 184
diff changeset
1000 if (entry->protocol)
75eebb3b0592 2003-6-24 Brian Masney <masneyb@gftp.org>
masneyb
parents: 184
diff changeset
1001 g_free (entry->protocol);
75eebb3b0592 2003-6-24 Brian Masney <masneyb@gftp.org>
masneyb
parents: 184
diff changeset
1002
75eebb3b0592 2003-6-24 Brian Masney <masneyb@gftp.org>
masneyb
parents: 184
diff changeset
1003 if (entry->local_options_vars != NULL)
75eebb3b0592 2003-6-24 Brian Masney <masneyb@gftp.org>
masneyb
parents: 184
diff changeset
1004 {
201
0098dae654a5 2003-6-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 199
diff changeset
1005 gftp_config_free_options (entry->local_options_vars,
0098dae654a5 2003-6-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 199
diff changeset
1006 entry->local_options_hash,
0098dae654a5 2003-6-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 199
diff changeset
1007 entry->num_local_options_vars);
0098dae654a5 2003-6-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 199
diff changeset
1008
199
75eebb3b0592 2003-6-24 Brian Masney <masneyb@gftp.org>
masneyb
parents: 184
diff changeset
1009 entry->local_options_vars = NULL;
201
0098dae654a5 2003-6-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 199
diff changeset
1010 entry->local_options_hash = NULL;
199
75eebb3b0592 2003-6-24 Brian Masney <masneyb@gftp.org>
masneyb
parents: 184
diff changeset
1011 entry->num_local_options_vars = 0;
75eebb3b0592 2003-6-24 Brian Masney <masneyb@gftp.org>
masneyb
parents: 184
diff changeset
1012 }
75eebb3b0592 2003-6-24 Brian Masney <masneyb@gftp.org>
masneyb
parents: 184
diff changeset
1013 }
75eebb3b0592 2003-6-24 Brian Masney <masneyb@gftp.org>
masneyb
parents: 184
diff changeset
1014
201
0098dae654a5 2003-6-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 199
diff changeset
1015
0098dae654a5 2003-6-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 199
diff changeset
1016 void
0098dae654a5 2003-6-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 199
diff changeset
1017 gftp_shutdown (void)
0098dae654a5 2003-6-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 199
diff changeset
1018 {
0098dae654a5 2003-6-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 199
diff changeset
1019 gftp_config_vars * cv;
0098dae654a5 2003-6-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 199
diff changeset
1020 GList * templist;
0098dae654a5 2003-6-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 199
diff changeset
1021
0098dae654a5 2003-6-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 199
diff changeset
1022 if (gftp_logfd != NULL)
0098dae654a5 2003-6-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 199
diff changeset
1023 fclose (gftp_logfd);
0098dae654a5 2003-6-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 199
diff changeset
1024
0098dae654a5 2003-6-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 199
diff changeset
1025 gftp_clear_cache_files ();
0098dae654a5 2003-6-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 199
diff changeset
1026
0098dae654a5 2003-6-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 199
diff changeset
1027 if (gftp_configuration_changed)
0098dae654a5 2003-6-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 199
diff changeset
1028 gftp_write_config_file ();
0098dae654a5 2003-6-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 199
diff changeset
1029
0098dae654a5 2003-6-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 199
diff changeset
1030 #ifdef WITH_DMALLOC
0098dae654a5 2003-6-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 199
diff changeset
1031 if (gftp_global_options_htable != NULL)
0098dae654a5 2003-6-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 199
diff changeset
1032 g_hash_table_destroy (gftp_global_options_htable);
0098dae654a5 2003-6-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 199
diff changeset
1033
0098dae654a5 2003-6-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 199
diff changeset
1034 if (gftp_config_list_htable != NULL)
0098dae654a5 2003-6-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 199
diff changeset
1035 g_hash_table_destroy (gftp_config_list_htable);
0098dae654a5 2003-6-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 199
diff changeset
1036
0098dae654a5 2003-6-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 199
diff changeset
1037 if (gftp_bookmarks_htable != NULL)
0098dae654a5 2003-6-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 199
diff changeset
1038 g_hash_table_destroy (gftp_bookmarks_htable);
0098dae654a5 2003-6-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 199
diff changeset
1039
0098dae654a5 2003-6-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 199
diff changeset
1040 for (templist = gftp_options_list;
0098dae654a5 2003-6-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 199
diff changeset
1041 templist != NULL;
0098dae654a5 2003-6-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 199
diff changeset
1042 templist = templist->next)
0098dae654a5 2003-6-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 199
diff changeset
1043 {
0098dae654a5 2003-6-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 199
diff changeset
1044 cv = templist->data;
0098dae654a5 2003-6-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 199
diff changeset
1045 gftp_config_free_options (cv, NULL, -1);
0098dae654a5 2003-6-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 199
diff changeset
1046 }
0098dae654a5 2003-6-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 199
diff changeset
1047
0098dae654a5 2003-6-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 199
diff changeset
1048 gftp_bookmarks_destroy (gftp_bookmarks);
0098dae654a5 2003-6-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 199
diff changeset
1049
0098dae654a5 2003-6-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 199
diff changeset
1050 dmalloc_shutdown ();
0098dae654a5 2003-6-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 199
diff changeset
1051 #endif
0098dae654a5 2003-6-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 199
diff changeset
1052
0098dae654a5 2003-6-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 199
diff changeset
1053 exit (0);
0098dae654a5 2003-6-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 199
diff changeset
1054 }
0098dae654a5 2003-6-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 199
diff changeset
1055