annotate lib/misc.c @ 864:c71bc7d32ce5

2006-11-30 Brian Masney <masneyb@gftp.org> * docs/sample.gftp/Makefile.am docs/sample.gftp/gftp-16x16.png docs/sample.gftp/gftp-22x22.png docs/sample.gftp/gftp-24x24.png docs/sample.gftp/gftp-32x32.png docs/sample.gftp/gftp-48x48.png docs/sample.gftp/gftp-scalable.svg docs/gftp.desktop docs/sample.gftp/gftp-mini-logo.png docs/sample.gftp/gftp-mini-logo.xpm - added new icons for gftp from Tango Friday theme. (closes #370627)
author masneyb
date Sat, 23 Dec 2006 19:29:16 +0000
parents 5e3005923374
children 2d4e6fca8e7c
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
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
20 #include "gftp.h"
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
21 #include "options.h"
516
fbb5a02beddb 2004-7-26 Brian Masney <masneyb@gftp.org>
masneyb
parents: 499
diff changeset
22 static const char cvsid[] = "$Id$";
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
23
328
51bb530a100c 2003-12-7 Brian Masney <masneyb@gftp.org>
masneyb
parents: 325
diff changeset
24 #ifdef HAVE_INTL_PRINTF
289
5f66f09e5194 2003-10-17 Brian Masney <masneyb@gftp.org>
masneyb
parents: 260
diff changeset
25
5f66f09e5194 2003-10-17 Brian Masney <masneyb@gftp.org>
masneyb
parents: 260
diff changeset
26 char *
5f66f09e5194 2003-10-17 Brian Masney <masneyb@gftp.org>
masneyb
parents: 260
diff changeset
27 insert_commas (off_t number, char *dest_str, size_t dest_len)
5f66f09e5194 2003-10-17 Brian Masney <masneyb@gftp.org>
masneyb
parents: 260
diff changeset
28 {
5f66f09e5194 2003-10-17 Brian Masney <masneyb@gftp.org>
masneyb
parents: 260
diff changeset
29 if (dest_str != NULL)
532
bccfdbfaac00 2004-8-17 Brian Masney <masneyb@gftp.org>
masneyb
parents: 516
diff changeset
30 g_snprintf (dest_str, dest_len, GFTP_OFF_T_INTL_PRINTF_MOD, number);
289
5f66f09e5194 2003-10-17 Brian Masney <masneyb@gftp.org>
masneyb
parents: 260
diff changeset
31 else
532
bccfdbfaac00 2004-8-17 Brian Masney <masneyb@gftp.org>
masneyb
parents: 516
diff changeset
32 dest_str = g_strdup_printf (GFTP_OFF_T_INTL_PRINTF_MOD, number);
289
5f66f09e5194 2003-10-17 Brian Masney <masneyb@gftp.org>
masneyb
parents: 260
diff changeset
33
5f66f09e5194 2003-10-17 Brian Masney <masneyb@gftp.org>
masneyb
parents: 260
diff changeset
34 return (dest_str);
5f66f09e5194 2003-10-17 Brian Masney <masneyb@gftp.org>
masneyb
parents: 260
diff changeset
35 }
5f66f09e5194 2003-10-17 Brian Masney <masneyb@gftp.org>
masneyb
parents: 260
diff changeset
36
5f66f09e5194 2003-10-17 Brian Masney <masneyb@gftp.org>
masneyb
parents: 260
diff changeset
37 #else
5f66f09e5194 2003-10-17 Brian Masney <masneyb@gftp.org>
masneyb
parents: 260
diff changeset
38
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
39 char *
14
83090328581e * More largefile support. Hopefully all that is left is the configure stuff
masneyb
parents: 13
diff changeset
40 insert_commas (off_t number, char *dest_str, size_t dest_len)
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
41 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
42 char *frompos, *topos, src[50], *dest;
460
075f89b4395c 2004-4-14 Brian Masney <masneyb@gftp.org>
masneyb
parents: 451
diff changeset
43 size_t num, rem, srclen;
765
d553d14a2565 2006-7-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 682
diff changeset
44 size_t len, i;
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
45
516
fbb5a02beddb 2004-7-26 Brian Masney <masneyb@gftp.org>
masneyb
parents: 499
diff changeset
46 g_snprintf (src, sizeof (src), GFTP_OFF_T_PRINTF_MOD, number);
220
6de9a8280aa4 2003-7-10 Brian Masney <masneyb@gftp.org>
masneyb
parents: 207
diff changeset
47
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
48 if (dest_str != NULL)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
49 *dest_str = '\0';
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
50
220
6de9a8280aa4 2003-7-10 Brian Masney <masneyb@gftp.org>
masneyb
parents: 207
diff changeset
51 len = strlen (src);
6de9a8280aa4 2003-7-10 Brian Masney <masneyb@gftp.org>
masneyb
parents: 207
diff changeset
52 if (len == 0)
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
53 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
54 if (dest_str != NULL)
249
094e83b55cb1 2003-8-7 Brian Masney <masneyb@gftp.org>
masneyb
parents: 247
diff changeset
55 {
094e83b55cb1 2003-8-7 Brian Masney <masneyb@gftp.org>
masneyb
parents: 247
diff changeset
56 strncpy (dest_str, "0", dest_len);
094e83b55cb1 2003-8-7 Brian Masney <masneyb@gftp.org>
masneyb
parents: 247
diff changeset
57 dest_str[dest_len - 1] = '\0';
094e83b55cb1 2003-8-7 Brian Masney <masneyb@gftp.org>
masneyb
parents: 247
diff changeset
58 }
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
59 else
56
a12bcbc2fce4 2002-11-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
60 dest_str = g_strdup ("0");
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
61 return (dest_str);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
62 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
63
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
64 len += len / 3;
220
6de9a8280aa4 2003-7-10 Brian Masney <masneyb@gftp.org>
masneyb
parents: 207
diff changeset
65
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
66 if (dest_str != NULL && len > dest_len)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
67 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
68
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
69 for (i=0; i<dest_len - 1; i++)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
70 dest_str[i] = 'X';
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
71 dest_str[dest_len - 1] = '\0';
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
72 return (dest_str);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
73 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
74
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
75 if (dest_str == NULL)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
76 dest = g_malloc0 (len);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
77 else
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
78 dest = dest_str;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
79
460
075f89b4395c 2004-4-14 Brian Masney <masneyb@gftp.org>
masneyb
parents: 451
diff changeset
80 srclen = strlen (src);
075f89b4395c 2004-4-14 Brian Masney <masneyb@gftp.org>
masneyb
parents: 451
diff changeset
81 num = srclen / 3 - 1;
075f89b4395c 2004-4-14 Brian Masney <masneyb@gftp.org>
masneyb
parents: 451
diff changeset
82 rem = srclen % 3;
075f89b4395c 2004-4-14 Brian Masney <masneyb@gftp.org>
masneyb
parents: 451
diff changeset
83
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
84 frompos = src;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
85 topos = dest;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
86 for (i = 0; i < rem; i++)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
87 *topos++ = *frompos++;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
88
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
89 if (*frompos != '\0')
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
90 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
91 if (rem != 0)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
92 *topos++ = ',';
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
93 while (num > 0)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
94 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
95 for (i = 0; i < 3; i++)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
96 *topos++ = *frompos++;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
97 *topos++ = ',';
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
98 num--;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
99 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
100 for (i = 0; i < 3; i++)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
101 *topos++ = *frompos++;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
102 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
103 *topos = '\0';
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
104 return (dest);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
105 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
106
289
5f66f09e5194 2003-10-17 Brian Masney <masneyb@gftp.org>
masneyb
parents: 260
diff changeset
107 #endif
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
108
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
109 char *
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
110 alltrim (char *str)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
111 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
112 char *pos, *newpos;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
113 int diff;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
114
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
115 pos = str + strlen (str) - 1;
87
6df043359b41 2003-1-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 84
diff changeset
116 while (pos >= str && (*pos == ' ' || *pos == '\t'))
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
117 *pos-- = '\0';
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
118
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
119 pos = str;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
120 diff = 0;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
121 while (*pos++ == ' ')
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
122 diff++;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
123
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
124 if (diff == 0)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
125 return (str);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
126
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
127 pos = str + diff;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
128 newpos = str;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
129 while (*pos != '\0')
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
130 *newpos++ = *pos++;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
131 *newpos = '\0';
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
132
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
133 return (str);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
134 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
135
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
136
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
137 char *
555
7f54d0c0edbc 2004-9-17 Brian Masney <masneyb@gftp.org>
masneyb
parents: 547
diff changeset
138 gftp_expand_path (gftp_request * request, const char *src)
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
139 {
307
76c912483d1d 2003-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 303
diff changeset
140 char *str, *pos, *endpos, *prevpos, *newstr, *tempstr, *ntoken,
76c912483d1d 2003-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 303
diff changeset
141 tempchar;
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
142 struct passwd *pw;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
143
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
144 pw = NULL;
124
65048c959029 2003-4-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 122
diff changeset
145 str = g_strdup (src);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
146
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
147 if (*str == '~')
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
148 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
149 if (*(str + 1) == '/' || *(str + 1) == '\0')
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
150 pw = getpwuid (geteuid ());
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
151 else
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
152 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
153 if ((pos = strchr (str, '/')) != NULL)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
154 *pos = '\0';
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
155
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
156 pw = getpwnam (str + 1);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
157
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
158 if (pos != NULL)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
159 *pos = '/';
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
160 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
161 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
162
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
163 endpos = str;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
164 newstr = NULL;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
165 while ((pos = strchr (endpos, '/')) != NULL)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
166 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
167 pos++;
204
9b2de8d3fafe 2003-6-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 203
diff changeset
168
307
76c912483d1d 2003-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 303
diff changeset
169 for (ntoken = pos; *ntoken == '/'; ntoken++);
76c912483d1d 2003-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 303
diff changeset
170
76c912483d1d 2003-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 303
diff changeset
171 if ((endpos = strchr (ntoken, '/')) == NULL)
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
172 endpos = pos + strlen (pos);
204
9b2de8d3fafe 2003-6-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 203
diff changeset
173
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
174 tempchar = *endpos;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
175 *endpos = '\0';
204
9b2de8d3fafe 2003-6-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 203
diff changeset
176
307
76c912483d1d 2003-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 303
diff changeset
177 if (strcmp (ntoken, "..") == 0)
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
178 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
179 if (newstr != NULL && (prevpos = strrchr (newstr, '/')) != NULL)
307
76c912483d1d 2003-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 303
diff changeset
180 {
76c912483d1d 2003-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 303
diff changeset
181 *prevpos = '\0';
76c912483d1d 2003-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 303
diff changeset
182 if (*newstr == '\0')
76c912483d1d 2003-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 303
diff changeset
183 {
76c912483d1d 2003-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 303
diff changeset
184 g_free (newstr);
76c912483d1d 2003-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 303
diff changeset
185 newstr = NULL;
76c912483d1d 2003-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 303
diff changeset
186 }
76c912483d1d 2003-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 303
diff changeset
187 }
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
188 }
307
76c912483d1d 2003-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 303
diff changeset
189 else if (strcmp (ntoken, ".") != 0)
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
190 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
191 if (newstr == NULL)
56
a12bcbc2fce4 2002-11-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
192 newstr = g_strdup (pos - 1);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
193 else
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
194 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
195 tempstr = g_strconcat (newstr, pos - 1, NULL);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
196 g_free (newstr);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
197 newstr = tempstr;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
198 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
199 }
204
9b2de8d3fafe 2003-6-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 203
diff changeset
200
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
201 *endpos = tempchar;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
202 if (*endpos == '\0')
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
203 break;
204
9b2de8d3fafe 2003-6-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 203
diff changeset
204
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
205 endpos = pos + 1;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
206 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
207
204
9b2de8d3fafe 2003-6-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 203
diff changeset
208 if (endpos != NULL && *endpos != '\0' && newstr == NULL)
9b2de8d3fafe 2003-6-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 203
diff changeset
209 {
9b2de8d3fafe 2003-6-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 203
diff changeset
210 if (strcmp (endpos, "..") == 0)
307
76c912483d1d 2003-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 303
diff changeset
211 newstr = g_strdup ("/");
204
9b2de8d3fafe 2003-6-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 203
diff changeset
212 else
9b2de8d3fafe 2003-6-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 203
diff changeset
213 newstr = g_strdup (endpos);
9b2de8d3fafe 2003-6-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 203
diff changeset
214 }
9b2de8d3fafe 2003-6-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 203
diff changeset
215
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
216 if (newstr == NULL || *newstr == '\0')
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
217 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
218 if (newstr != NULL)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
219 g_free (newstr);
204
9b2de8d3fafe 2003-6-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 203
diff changeset
220
247
f41650dc896c 2003-8-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 245
diff changeset
221 newstr = g_strdup ("/");
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
222 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
223
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
224 g_free (str);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
225
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
226 if (pw != NULL)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
227 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
228 if ((pos = strchr (newstr, '/')) == NULL)
124
65048c959029 2003-4-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 122
diff changeset
229 str = g_strdup (pw->pw_dir);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
230 else
555
7f54d0c0edbc 2004-9-17 Brian Masney <masneyb@gftp.org>
masneyb
parents: 547
diff changeset
231 str = gftp_build_path (request, pw->pw_dir, pos, NULL);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
232
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
233 g_free (newstr);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
234 newstr = str;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
235 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
236
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
237 return (newstr);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
238 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
239
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
240
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
241 void
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
242 make_nonnull (char **str)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
243 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
244 if (*str == NULL)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
245 *str = g_malloc0 (1);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
246 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
247
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
248
821
b282e346bd25 2006-10-1 Brian Masney <masneyb@gftp.org>
masneyb
parents: 779
diff changeset
249 /* FIXME - Possible use the libpcre library. If it isn't used, then clean
b282e346bd25 2006-10-1 Brian Masney <masneyb@gftp.org>
masneyb
parents: 779
diff changeset
250 this function up some more. */
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
251 int
821
b282e346bd25 2006-10-1 Brian Masney <masneyb@gftp.org>
masneyb
parents: 779
diff changeset
252 gftp_match_filespec (gftp_request * request, const char *filename,
b282e346bd25 2006-10-1 Brian Masney <masneyb@gftp.org>
masneyb
parents: 779
diff changeset
253 const char *filespec)
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
254 {
374
d207b8241e96 2003-1-21 Brian Masney <masneyb@gftp.org>
masneyb
parents: 372
diff changeset
255 const char *filepos, *wcpos, *pos;
d207b8241e96 2003-1-21 Brian Masney <masneyb@gftp.org>
masneyb
parents: 372
diff changeset
256 char search_str[20], *newpos;
821
b282e346bd25 2006-10-1 Brian Masney <masneyb@gftp.org>
masneyb
parents: 779
diff changeset
257 intptr_t show_hidden_files;
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
258 size_t len, curlen;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
259
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
260 if (filename == NULL || *filename == '\0' ||
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
261 filespec == NULL || *filespec == '\0')
821
b282e346bd25 2006-10-1 Brian Masney <masneyb@gftp.org>
masneyb
parents: 779
diff changeset
262 return (1);
b282e346bd25 2006-10-1 Brian Masney <masneyb@gftp.org>
masneyb
parents: 779
diff changeset
263
b282e346bd25 2006-10-1 Brian Masney <masneyb@gftp.org>
masneyb
parents: 779
diff changeset
264 gftp_lookup_request_option (request, "show_hidden_files", &show_hidden_files);
b282e346bd25 2006-10-1 Brian Masney <masneyb@gftp.org>
masneyb
parents: 779
diff changeset
265 if (!show_hidden_files && *filename == '.' && strcmp (filename, "..") != 0)
b282e346bd25 2006-10-1 Brian Masney <masneyb@gftp.org>
masneyb
parents: 779
diff changeset
266 return (0);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
267
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
268 filepos = filename;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
269 wcpos = filespec;
821
b282e346bd25 2006-10-1 Brian Masney <masneyb@gftp.org>
masneyb
parents: 779
diff changeset
270 while (1)
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
271 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
272 if (*wcpos == '\0')
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
273 return (1);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
274 else if (*filepos == '\0')
821
b282e346bd25 2006-10-1 Brian Masney <masneyb@gftp.org>
masneyb
parents: 779
diff changeset
275 return (0);
b282e346bd25 2006-10-1 Brian Masney <masneyb@gftp.org>
masneyb
parents: 779
diff changeset
276 else if (*wcpos == '?')
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
277 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
278 wcpos++;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
279 filepos++;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
280 }
821
b282e346bd25 2006-10-1 Brian Masney <masneyb@gftp.org>
masneyb
parents: 779
diff changeset
281 else if (*wcpos == '*' && *(wcpos+1) == '\0')
b282e346bd25 2006-10-1 Brian Masney <masneyb@gftp.org>
masneyb
parents: 779
diff changeset
282 return (1);
b282e346bd25 2006-10-1 Brian Masney <masneyb@gftp.org>
masneyb
parents: 779
diff changeset
283 else if (*wcpos == '*')
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
284 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
285 len = sizeof (search_str);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
286 for (pos = wcpos + 1, newpos = search_str, curlen = 0;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
287 *pos != '*' && *pos != '?' && *pos != '\0' && curlen < len;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
288 curlen++, *newpos++ = *pos++);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
289 *newpos = '\0';
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
290
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
291 if ((filepos = strstr (filepos, search_str)) == NULL)
821
b282e346bd25 2006-10-1 Brian Masney <masneyb@gftp.org>
masneyb
parents: 779
diff changeset
292 return (0);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
293 wcpos += curlen + 1;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
294 filepos += curlen;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
295 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
296 else if(*wcpos++ != *filepos++)
821
b282e346bd25 2006-10-1 Brian Masney <masneyb@gftp.org>
masneyb
parents: 779
diff changeset
297 return (0);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
298 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
299 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
300
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
301
243
b42e7233533a 2003-7-31 Brian Masney <masneyb@gftp.org>
masneyb
parents: 227
diff changeset
302 static void
b42e7233533a 2003-7-31 Brian Masney <masneyb@gftp.org>
masneyb
parents: 227
diff changeset
303 gftp_info (void)
b42e7233533a 2003-7-31 Brian Masney <masneyb@gftp.org>
masneyb
parents: 227
diff changeset
304 {
260
71d0098c3735 2003-8-17 Brian Masney <masneyb@gftp.org>
masneyb
parents: 249
diff changeset
305 int i;
71d0098c3735 2003-8-17 Brian Masney <masneyb@gftp.org>
masneyb
parents: 249
diff changeset
306
243
b42e7233533a 2003-7-31 Brian Masney <masneyb@gftp.org>
masneyb
parents: 227
diff changeset
307 printf ("%s\n", gftp_version);
b42e7233533a 2003-7-31 Brian Masney <masneyb@gftp.org>
masneyb
parents: 227
diff changeset
308
307
76c912483d1d 2003-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 303
diff changeset
309 #ifdef _REENTRANT
76c912483d1d 2003-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 303
diff changeset
310 printf ("#define _REENTRANT\n");
76c912483d1d 2003-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 303
diff changeset
311 #endif
76c912483d1d 2003-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 303
diff changeset
312
289
5f66f09e5194 2003-10-17 Brian Masney <masneyb@gftp.org>
masneyb
parents: 260
diff changeset
313 #ifdef _GNU_SOURCE
5f66f09e5194 2003-10-17 Brian Masney <masneyb@gftp.org>
masneyb
parents: 260
diff changeset
314 printf ("#define _GNU_SOURCE\n");
5f66f09e5194 2003-10-17 Brian Masney <masneyb@gftp.org>
masneyb
parents: 260
diff changeset
315 #endif
5f66f09e5194 2003-10-17 Brian Masney <masneyb@gftp.org>
masneyb
parents: 260
diff changeset
316
243
b42e7233533a 2003-7-31 Brian Masney <masneyb@gftp.org>
masneyb
parents: 227
diff changeset
317 #ifdef _LARGEFILE_SOURCE
260
71d0098c3735 2003-8-17 Brian Masney <masneyb@gftp.org>
masneyb
parents: 249
diff changeset
318 printf ("#define _LARGEFILE_SOURCE\n");
243
b42e7233533a 2003-7-31 Brian Masney <masneyb@gftp.org>
masneyb
parents: 227
diff changeset
319 #endif
b42e7233533a 2003-7-31 Brian Masney <masneyb@gftp.org>
masneyb
parents: 227
diff changeset
320
b42e7233533a 2003-7-31 Brian Masney <masneyb@gftp.org>
masneyb
parents: 227
diff changeset
321 #ifdef _FILE_OFFSET_BITS
b42e7233533a 2003-7-31 Brian Masney <masneyb@gftp.org>
masneyb
parents: 227
diff changeset
322 printf ("#define _FILE_OFFSET_BITS %d\n", _FILE_OFFSET_BITS);
b42e7233533a 2003-7-31 Brian Masney <masneyb@gftp.org>
masneyb
parents: 227
diff changeset
323 #endif
b42e7233533a 2003-7-31 Brian Masney <masneyb@gftp.org>
masneyb
parents: 227
diff changeset
324
b42e7233533a 2003-7-31 Brian Masney <masneyb@gftp.org>
masneyb
parents: 227
diff changeset
325 printf ("sizeof (off_t) = %d\n", sizeof (off_t));
b42e7233533a 2003-7-31 Brian Masney <masneyb@gftp.org>
masneyb
parents: 227
diff changeset
326
b42e7233533a 2003-7-31 Brian Masney <masneyb@gftp.org>
masneyb
parents: 227
diff changeset
327 #ifdef HAVE_GETADDRINFO
b42e7233533a 2003-7-31 Brian Masney <masneyb@gftp.org>
masneyb
parents: 227
diff changeset
328 printf ("#define HAVE_GETADDRINFO\n");
b42e7233533a 2003-7-31 Brian Masney <masneyb@gftp.org>
masneyb
parents: 227
diff changeset
329 #endif
b42e7233533a 2003-7-31 Brian Masney <masneyb@gftp.org>
masneyb
parents: 227
diff changeset
330
b42e7233533a 2003-7-31 Brian Masney <masneyb@gftp.org>
masneyb
parents: 227
diff changeset
331 #ifdef HAVE_GAI_STRERROR
b42e7233533a 2003-7-31 Brian Masney <masneyb@gftp.org>
masneyb
parents: 227
diff changeset
332 printf ("#define HAVE_GAI_STRERROR\n");
b42e7233533a 2003-7-31 Brian Masney <masneyb@gftp.org>
masneyb
parents: 227
diff changeset
333 #endif
b42e7233533a 2003-7-31 Brian Masney <masneyb@gftp.org>
masneyb
parents: 227
diff changeset
334
b42e7233533a 2003-7-31 Brian Masney <masneyb@gftp.org>
masneyb
parents: 227
diff changeset
335 #ifdef HAVE_GETDTABLESIZE
b42e7233533a 2003-7-31 Brian Masney <masneyb@gftp.org>
masneyb
parents: 227
diff changeset
336 printf ("#define HAVE_GETDTABLESIZE\n");
b42e7233533a 2003-7-31 Brian Masney <masneyb@gftp.org>
masneyb
parents: 227
diff changeset
337 #endif
b42e7233533a 2003-7-31 Brian Masney <masneyb@gftp.org>
masneyb
parents: 227
diff changeset
338
b42e7233533a 2003-7-31 Brian Masney <masneyb@gftp.org>
masneyb
parents: 227
diff changeset
339 #ifdef G_HAVE_GINT64
b42e7233533a 2003-7-31 Brian Masney <masneyb@gftp.org>
masneyb
parents: 227
diff changeset
340 printf ("#define G_HAVE_GINT64\n");
b42e7233533a 2003-7-31 Brian Masney <masneyb@gftp.org>
masneyb
parents: 227
diff changeset
341 #endif
b42e7233533a 2003-7-31 Brian Masney <masneyb@gftp.org>
masneyb
parents: 227
diff changeset
342
b42e7233533a 2003-7-31 Brian Masney <masneyb@gftp.org>
masneyb
parents: 227
diff changeset
343 #ifdef HAVE_LIBREADLINE
b42e7233533a 2003-7-31 Brian Masney <masneyb@gftp.org>
masneyb
parents: 227
diff changeset
344 printf ("#define HAVE_LIBREADLINE\n");
b42e7233533a 2003-7-31 Brian Masney <masneyb@gftp.org>
masneyb
parents: 227
diff changeset
345 #endif
b42e7233533a 2003-7-31 Brian Masney <masneyb@gftp.org>
masneyb
parents: 227
diff changeset
346
b42e7233533a 2003-7-31 Brian Masney <masneyb@gftp.org>
masneyb
parents: 227
diff changeset
347 #ifdef ENABLE_NLS
b42e7233533a 2003-7-31 Brian Masney <masneyb@gftp.org>
masneyb
parents: 227
diff changeset
348 printf ("#define ENABLE_NLS\n");
b42e7233533a 2003-7-31 Brian Masney <masneyb@gftp.org>
masneyb
parents: 227
diff changeset
349 #endif
b42e7233533a 2003-7-31 Brian Masney <masneyb@gftp.org>
masneyb
parents: 227
diff changeset
350
b42e7233533a 2003-7-31 Brian Masney <masneyb@gftp.org>
masneyb
parents: 227
diff changeset
351 #ifdef HAVE_GETTEXT
b42e7233533a 2003-7-31 Brian Masney <masneyb@gftp.org>
masneyb
parents: 227
diff changeset
352 printf ("#define HAVE_GETTEXT\n");
b42e7233533a 2003-7-31 Brian Masney <masneyb@gftp.org>
masneyb
parents: 227
diff changeset
353 #endif
b42e7233533a 2003-7-31 Brian Masney <masneyb@gftp.org>
masneyb
parents: 227
diff changeset
354
328
51bb530a100c 2003-12-7 Brian Masney <masneyb@gftp.org>
masneyb
parents: 325
diff changeset
355 #ifdef HAVE_INTL_PRINTF
51bb530a100c 2003-12-7 Brian Masney <masneyb@gftp.org>
masneyb
parents: 325
diff changeset
356 printf ("#define HAVE_INTL_PRINTF\n");
51bb530a100c 2003-12-7 Brian Masney <masneyb@gftp.org>
masneyb
parents: 325
diff changeset
357 #endif
51bb530a100c 2003-12-7 Brian Masney <masneyb@gftp.org>
masneyb
parents: 325
diff changeset
358
243
b42e7233533a 2003-7-31 Brian Masney <masneyb@gftp.org>
masneyb
parents: 227
diff changeset
359 printf ("glib version: %d.%d.%d\n", GLIB_MAJOR_VERSION, GLIB_MINOR_VERSION,
b42e7233533a 2003-7-31 Brian Masney <masneyb@gftp.org>
masneyb
parents: 227
diff changeset
360 GLIB_MICRO_VERSION);
b42e7233533a 2003-7-31 Brian Masney <masneyb@gftp.org>
masneyb
parents: 227
diff changeset
361
b42e7233533a 2003-7-31 Brian Masney <masneyb@gftp.org>
masneyb
parents: 227
diff changeset
362 printf ("PTY implementation: %s\n", gftp_get_pty_impl ());
b42e7233533a 2003-7-31 Brian Masney <masneyb@gftp.org>
masneyb
parents: 227
diff changeset
363
b42e7233533a 2003-7-31 Brian Masney <masneyb@gftp.org>
masneyb
parents: 227
diff changeset
364 #ifdef USE_SSL
653
07dc89f95076 2004-12-31 Brian Masney <masneyb@gftp.org>
masneyb
parents: 612
diff changeset
365 printf ("OpenSSL version: %s\n", OPENSSL_VERSION_TEXT);
243
b42e7233533a 2003-7-31 Brian Masney <masneyb@gftp.org>
masneyb
parents: 227
diff changeset
366 #endif
260
71d0098c3735 2003-8-17 Brian Masney <masneyb@gftp.org>
masneyb
parents: 249
diff changeset
367
71d0098c3735 2003-8-17 Brian Masney <masneyb@gftp.org>
masneyb
parents: 249
diff changeset
368 printf ("Enabled protocols: ");
71d0098c3735 2003-8-17 Brian Masney <masneyb@gftp.org>
masneyb
parents: 249
diff changeset
369 for (i=0; gftp_protocols[i].name != NULL; i++)
71d0098c3735 2003-8-17 Brian Masney <masneyb@gftp.org>
masneyb
parents: 249
diff changeset
370 {
71d0098c3735 2003-8-17 Brian Masney <masneyb@gftp.org>
masneyb
parents: 249
diff changeset
371 printf ("%s ", gftp_protocols[i].name);
71d0098c3735 2003-8-17 Brian Masney <masneyb@gftp.org>
masneyb
parents: 249
diff changeset
372 }
71d0098c3735 2003-8-17 Brian Masney <masneyb@gftp.org>
masneyb
parents: 249
diff changeset
373 printf ("\n");
243
b42e7233533a 2003-7-31 Brian Masney <masneyb@gftp.org>
masneyb
parents: 227
diff changeset
374 }
b42e7233533a 2003-7-31 Brian Masney <masneyb@gftp.org>
masneyb
parents: 227
diff changeset
375
b42e7233533a 2003-7-31 Brian Masney <masneyb@gftp.org>
masneyb
parents: 227
diff changeset
376
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
377 int
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
378 gftp_parse_command_line (int *argc, char ***argv)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
379 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
380 if (*argc > 1)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
381 {
87
6df043359b41 2003-1-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 84
diff changeset
382 if (strcmp (argv[0][1], "--help") == 0 ||
6df043359b41 2003-1-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 84
diff changeset
383 strcmp (argv[0][1], "-h") == 0)
349
3fccdc9eb16f 2003-1-4 Brian Masney <masneyb@gftp.org>
masneyb
parents: 330
diff changeset
384 {
3fccdc9eb16f 2003-1-4 Brian Masney <masneyb@gftp.org>
masneyb
parents: 330
diff changeset
385 gftp_usage ();
3fccdc9eb16f 2003-1-4 Brian Masney <masneyb@gftp.org>
masneyb
parents: 330
diff changeset
386 exit (0);
3fccdc9eb16f 2003-1-4 Brian Masney <masneyb@gftp.org>
masneyb
parents: 330
diff changeset
387 }
87
6df043359b41 2003-1-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 84
diff changeset
388 else if (strcmp (argv[0][1], "--version") == 0 ||
6df043359b41 2003-1-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 84
diff changeset
389 strcmp (argv[0][1], "-v") == 0)
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
390 {
349
3fccdc9eb16f 2003-1-4 Brian Masney <masneyb@gftp.org>
masneyb
parents: 330
diff changeset
391 printf ("%s\n", gftp_version);
3fccdc9eb16f 2003-1-4 Brian Masney <masneyb@gftp.org>
masneyb
parents: 330
diff changeset
392 exit (0);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
393 }
243
b42e7233533a 2003-7-31 Brian Masney <masneyb@gftp.org>
masneyb
parents: 227
diff changeset
394 else if (strcmp (argv[0][1], "--info") == 0)
b42e7233533a 2003-7-31 Brian Masney <masneyb@gftp.org>
masneyb
parents: 227
diff changeset
395 {
b42e7233533a 2003-7-31 Brian Masney <masneyb@gftp.org>
masneyb
parents: 227
diff changeset
396 gftp_info ();
349
3fccdc9eb16f 2003-1-4 Brian Masney <masneyb@gftp.org>
masneyb
parents: 330
diff changeset
397 exit (0);
243
b42e7233533a 2003-7-31 Brian Masney <masneyb@gftp.org>
masneyb
parents: 227
diff changeset
398 }
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
399 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
400 return (0);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
401 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
402
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
403
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
404 void
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
405 gftp_usage (void)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
406 {
356
7cb3327f96f7 2003-1-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 349
diff changeset
407 printf (_("usage: gftp " GFTP_URL_USAGE "\n"));
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
408 exit (0);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
409 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
410
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
411
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
412 gint
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
413 string_hash_compare (gconstpointer path1, gconstpointer path2)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
414 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
415 return (strcmp ((char *) path1, (char *) path2) == 0);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
416 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
417
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
418
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
419 guint
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
420 string_hash_function (gconstpointer key)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
421 {
59
618423504fe0 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 58
diff changeset
422 guint ret;
618423504fe0 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 58
diff changeset
423 int i;
618423504fe0 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 58
diff changeset
424
618423504fe0 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 58
diff changeset
425 ret = 0;
87
6df043359b41 2003-1-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 84
diff changeset
426 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
427 ret += ((char *) key)[i];
618423504fe0 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 58
diff changeset
428
618423504fe0 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 58
diff changeset
429 return (ret);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
430 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
431
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
432
852
5e3005923374 2006-11-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 845
diff changeset
433 gint
5e3005923374 2006-11-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 845
diff changeset
434 uint_hash_compare (gconstpointer path1, gconstpointer path2)
5e3005923374 2006-11-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 845
diff changeset
435 {
5e3005923374 2006-11-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 845
diff changeset
436 return (GPOINTER_TO_UINT (path1) == GPOINTER_TO_UINT (path2));
5e3005923374 2006-11-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 845
diff changeset
437 }
5e3005923374 2006-11-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 845
diff changeset
438
5e3005923374 2006-11-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 845
diff changeset
439
5e3005923374 2006-11-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 845
diff changeset
440 guint
5e3005923374 2006-11-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 845
diff changeset
441 uint_hash_function (gconstpointer key)
5e3005923374 2006-11-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 845
diff changeset
442 {
5e3005923374 2006-11-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 845
diff changeset
443 return (GPOINTER_TO_UINT (key));
5e3005923374 2006-11-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 845
diff changeset
444 }
5e3005923374 2006-11-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 845
diff changeset
445
5e3005923374 2006-11-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 845
diff changeset
446
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
447 void
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
448 free_file_list (GList * filelist)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
449 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
450 gftp_file * tempfle;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
451 GList * templist;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
452
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
453 templist = filelist;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
454 while (templist != NULL)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
455 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
456 tempfle = templist->data;
598
fa0838b22b14 2004-10-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 555
diff changeset
457 gftp_file_destroy (tempfle, 1);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
458 templist = templist->next;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
459 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
460 g_list_free (filelist);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
461 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
462
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
463
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
464 gftp_file *
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
465 copy_fdata (gftp_file * fle)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
466 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
467 gftp_file * newfle;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
468
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
469 newfle = g_malloc0 (sizeof (*newfle));
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
470 memcpy (newfle, fle, sizeof (*newfle));
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
471
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
472 if (fle->file)
87
6df043359b41 2003-1-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 84
diff changeset
473 newfle->file = g_strdup (fle->file);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
474
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
475 if (fle->user)
87
6df043359b41 2003-1-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 84
diff changeset
476 newfle->user = g_strdup (fle->user);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
477
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
478 if (fle->group)
87
6df043359b41 2003-1-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 84
diff changeset
479 newfle->group = g_strdup (fle->group);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
480
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
481 if (fle->destfile)
87
6df043359b41 2003-1-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 84
diff changeset
482 newfle->destfile = g_strdup (fle->destfile);
6df043359b41 2003-1-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 84
diff changeset
483
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
484 return (newfle);
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 int
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
489 compare_request (gftp_request * request1, gftp_request * request2,
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
490 int compare_dirs)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
491 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
492 char *strarr[3][2];
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
493 int i, ret;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
494
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
495 ret = 1;
87
6df043359b41 2003-1-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 84
diff changeset
496 if (request1->protonum == request2->protonum &&
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
497 request1->port == request2->port)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
498 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
499 strarr[0][0] = request1->hostname;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
500 strarr[0][1] = request2->hostname;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
501 strarr[1][0] = request1->username;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
502 strarr[1][1] = request2->username;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
503 if (compare_dirs)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
504 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
505 strarr[2][0] = request1->directory;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
506 strarr[2][1] = request2->directory;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
507 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
508 else
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
509 strarr[2][0] = strarr[2][1] = "";
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
510
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
511 for (i = 0; i < 3; i++)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
512 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
513 if ((strarr[i][0] && !strarr[i][1]) ||
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
514 (!strarr[i][0] && strarr[i][1]))
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
515 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
516 ret = 0;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
517 break;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
518 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
519
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
520 if (strarr[i][0] && strarr[i][1] &&
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
521 strcmp (strarr[i][0], strarr[i][1]) != 0)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
522 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
523 ret = 0;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
524 break;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
525 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
526 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
527 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
528 else
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
529 ret = 0;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
530 return (ret);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
531 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
532
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
533
129
fe0b21c006f6 2003-4-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 125
diff changeset
534 gftp_transfer *
fe0b21c006f6 2003-4-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 125
diff changeset
535 gftp_tdata_new (void)
fe0b21c006f6 2003-4-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 125
diff changeset
536 {
227
a85a097bbb02 2003-7-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 220
diff changeset
537 #if GLIB_MAJOR_VERSION == 1
a85a097bbb02 2003-7-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 220
diff changeset
538 static GStaticMutex init_mutex = G_STATIC_MUTEX_INIT;
a85a097bbb02 2003-7-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 220
diff changeset
539 #endif
129
fe0b21c006f6 2003-4-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 125
diff changeset
540 gftp_transfer * tdata;
fe0b21c006f6 2003-4-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 125
diff changeset
541
fe0b21c006f6 2003-4-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 125
diff changeset
542 tdata = g_malloc0 (sizeof (*tdata));
227
a85a097bbb02 2003-7-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 220
diff changeset
543
a85a097bbb02 2003-7-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 220
diff changeset
544 #if GLIB_MAJOR_VERSION == 1
a85a097bbb02 2003-7-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 220
diff changeset
545 tdata->statmutex = init_mutex;
a85a097bbb02 2003-7-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 220
diff changeset
546 tdata->structmutex = init_mutex;
a85a097bbb02 2003-7-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 220
diff changeset
547 #else
168
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 162
diff changeset
548 g_static_mutex_init (&tdata->statmutex);
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 162
diff changeset
549 g_static_mutex_init (&tdata->structmutex);
227
a85a097bbb02 2003-7-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 220
diff changeset
550 #endif
a85a097bbb02 2003-7-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 220
diff changeset
551
129
fe0b21c006f6 2003-4-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 125
diff changeset
552 return (tdata);
fe0b21c006f6 2003-4-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 125
diff changeset
553 }
fe0b21c006f6 2003-4-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 125
diff changeset
554
fe0b21c006f6 2003-4-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 125
diff changeset
555
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
556 void
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
557 free_tdata (gftp_transfer * tdata)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
558 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
559 if (tdata->fromreq != NULL)
67
aa971a4bb16f 2002-11-27 Brian Masney <masneyb@gftp.org>
masneyb
parents: 66
diff changeset
560 gftp_request_destroy (tdata->fromreq, 1);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
561 if (tdata->toreq != NULL)
67
aa971a4bb16f 2002-11-27 Brian Masney <masneyb@gftp.org>
masneyb
parents: 66
diff changeset
562 gftp_request_destroy (tdata->toreq, 1);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
563 free_file_list (tdata->files);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
564 g_free (tdata);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
565 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
566
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
567
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
568 gftp_request *
368
af541d789f4c 2003-1-18 Brian Masney <masneyb@gftp.org>
masneyb
parents: 356
diff changeset
569 gftp_copy_request (gftp_request * req)
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
570 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
571 gftp_request * newreq;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
572
66
cd3e457cbc85 2002-11-26 Brian Masney <masneyb@gftp.org>
masneyb
parents: 65
diff changeset
573 newreq = gftp_request_new ();
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
574
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
575 if (req->hostname)
56
a12bcbc2fce4 2002-11-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
576 newreq->hostname = g_strdup (req->hostname);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
577 if (req->username)
56
a12bcbc2fce4 2002-11-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
578 newreq->username = g_strdup (req->username);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
579 if (req->password)
56
a12bcbc2fce4 2002-11-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
580 newreq->password = g_strdup (req->password);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
581 if (req->account)
56
a12bcbc2fce4 2002-11-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
582 newreq->account = g_strdup (req->account);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
583 if (req->directory)
56
a12bcbc2fce4 2002-11-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
584 newreq->directory = g_strdup (req->directory);
66
cd3e457cbc85 2002-11-26 Brian Masney <masneyb@gftp.org>
masneyb
parents: 65
diff changeset
585 newreq->port = req->port;
cd3e457cbc85 2002-11-26 Brian Masney <masneyb@gftp.org>
masneyb
parents: 65
diff changeset
586 newreq->use_proxy = req->use_proxy;
cd3e457cbc85 2002-11-26 Brian Masney <masneyb@gftp.org>
masneyb
parents: 65
diff changeset
587 newreq->logging_function = req->logging_function;
547
34a3f10d8bae 2004-9-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 535
diff changeset
588 newreq->ai_family = req->ai_family;
777
f6a3f5677339 2006-7-19 Brian Masney <masneyb@gftp.org>
masneyb
parents: 765
diff changeset
589
f6a3f5677339 2006-7-19 Brian Masney <masneyb@gftp.org>
masneyb
parents: 765
diff changeset
590 if (req->hostp)
f6a3f5677339 2006-7-19 Brian Masney <masneyb@gftp.org>
masneyb
parents: 765
diff changeset
591 {
f6a3f5677339 2006-7-19 Brian Masney <masneyb@gftp.org>
masneyb
parents: 765
diff changeset
592 #if defined (HAVE_GETADDRINFO) && defined (HAVE_GAI_STRERROR)
779
cb70c5abd8f3 2006-7-19 Brian Masney <masneyb@gftp.org>
masneyb
parents: 777
diff changeset
593 struct addrinfo *hostp = req->hostp;
cb70c5abd8f3 2006-7-19 Brian Masney <masneyb@gftp.org>
masneyb
parents: 777
diff changeset
594 struct addrinfo *newhostp = newreq->hostp;
cb70c5abd8f3 2006-7-19 Brian Masney <masneyb@gftp.org>
masneyb
parents: 777
diff changeset
595
cb70c5abd8f3 2006-7-19 Brian Masney <masneyb@gftp.org>
masneyb
parents: 777
diff changeset
596 while (hostp != NULL)
cb70c5abd8f3 2006-7-19 Brian Masney <masneyb@gftp.org>
masneyb
parents: 777
diff changeset
597 {
cb70c5abd8f3 2006-7-19 Brian Masney <masneyb@gftp.org>
masneyb
parents: 777
diff changeset
598 newhostp = g_malloc (sizeof(struct addrinfo));
cb70c5abd8f3 2006-7-19 Brian Masney <masneyb@gftp.org>
masneyb
parents: 777
diff changeset
599 memcpy (newhostp, hostp, sizeof (struct addrinfo));
cb70c5abd8f3 2006-7-19 Brian Masney <masneyb@gftp.org>
masneyb
parents: 777
diff changeset
600 newhostp->ai_addr = g_malloc (sizeof (struct sockaddr));
cb70c5abd8f3 2006-7-19 Brian Masney <masneyb@gftp.org>
masneyb
parents: 777
diff changeset
601 memcpy(newhostp->ai_addr, hostp->ai_addr, sizeof (struct sockaddr));
cb70c5abd8f3 2006-7-19 Brian Masney <masneyb@gftp.org>
masneyb
parents: 777
diff changeset
602 if (hostp->ai_canonname)
cb70c5abd8f3 2006-7-19 Brian Masney <masneyb@gftp.org>
masneyb
parents: 777
diff changeset
603 newhostp->ai_canonname = strdup(hostp->ai_canonname);
cb70c5abd8f3 2006-7-19 Brian Masney <masneyb@gftp.org>
masneyb
parents: 777
diff changeset
604
cb70c5abd8f3 2006-7-19 Brian Masney <masneyb@gftp.org>
masneyb
parents: 777
diff changeset
605 if (req->current_hostp == hostp)
cb70c5abd8f3 2006-7-19 Brian Masney <masneyb@gftp.org>
masneyb
parents: 777
diff changeset
606 newreq->current_hostp = newhostp;
cb70c5abd8f3 2006-7-19 Brian Masney <masneyb@gftp.org>
masneyb
parents: 777
diff changeset
607
cb70c5abd8f3 2006-7-19 Brian Masney <masneyb@gftp.org>
masneyb
parents: 777
diff changeset
608 hostp = hostp->ai_next; newhostp = newhostp->ai_next;
cb70c5abd8f3 2006-7-19 Brian Masney <masneyb@gftp.org>
masneyb
parents: 777
diff changeset
609 }
777
f6a3f5677339 2006-7-19 Brian Masney <masneyb@gftp.org>
masneyb
parents: 765
diff changeset
610 #else
779
cb70c5abd8f3 2006-7-19 Brian Masney <masneyb@gftp.org>
masneyb
parents: 777
diff changeset
611 newreq->hostp = g_malloc (sizeof (struct hostent));
cb70c5abd8f3 2006-7-19 Brian Masney <masneyb@gftp.org>
masneyb
parents: 777
diff changeset
612 memcpy(newreq->hostp, req->hostp, sizeof (struct hostent));
777
f6a3f5677339 2006-7-19 Brian Masney <masneyb@gftp.org>
masneyb
parents: 765
diff changeset
613 newreq->host = req->host;
f6a3f5677339 2006-7-19 Brian Masney <masneyb@gftp.org>
masneyb
parents: 765
diff changeset
614 newreq->curhost = req->curhost;
f6a3f5677339 2006-7-19 Brian Masney <masneyb@gftp.org>
masneyb
parents: 765
diff changeset
615 #endif
f6a3f5677339 2006-7-19 Brian Masney <masneyb@gftp.org>
masneyb
parents: 765
diff changeset
616 }
f6a3f5677339 2006-7-19 Brian Masney <masneyb@gftp.org>
masneyb
parents: 765
diff changeset
617 else
f6a3f5677339 2006-7-19 Brian Masney <masneyb@gftp.org>
masneyb
parents: 765
diff changeset
618 newreq->hostp = NULL;
f6a3f5677339 2006-7-19 Brian Masney <masneyb@gftp.org>
masneyb
parents: 765
diff changeset
619 newreq->free_hostp = 1;
151
2f15b3000dbc 2003-4-27 Brian Masney <masneyb@gftp.org>
masneyb
parents: 146
diff changeset
620
368
af541d789f4c 2003-1-18 Brian Masney <masneyb@gftp.org>
masneyb
parents: 356
diff changeset
621 gftp_copy_local_options (&newreq->local_options_vars,
af541d789f4c 2003-1-18 Brian Masney <masneyb@gftp.org>
masneyb
parents: 356
diff changeset
622 &newreq->local_options_hash,
429
1d45758e5cf5 2004-3-17 Brian Masney <masneyb@gftp.org>
masneyb
parents: 422
diff changeset
623 &newreq->num_local_options_vars,
368
af541d789f4c 2003-1-18 Brian Masney <masneyb@gftp.org>
masneyb
parents: 356
diff changeset
624 req->local_options_vars,
af541d789f4c 2003-1-18 Brian Masney <masneyb@gftp.org>
masneyb
parents: 356
diff changeset
625 req->num_local_options_vars);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
626
451
83cfffb2878a 2004-3-26 Brian Masney <masneyb@gftp.org>
masneyb
parents: 429
diff changeset
627 if (req->init != NULL && req->init (newreq) < 0)
173
4c288d05b26a 2003-6-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 168
diff changeset
628 {
4c288d05b26a 2003-6-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 168
diff changeset
629 gftp_request_destroy (newreq, 1);
4c288d05b26a 2003-6-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 168
diff changeset
630 return (NULL);
4c288d05b26a 2003-6-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 168
diff changeset
631 }
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
632
309
cc2eeb30b793 2003-11-7 Brian Masney <masneyb@gftp.org>
masneyb
parents: 307
diff changeset
633 gftp_copy_param_options (newreq, req);
cc2eeb30b793 2003-11-7 Brian Masney <masneyb@gftp.org>
masneyb
parents: 307
diff changeset
634
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
635 return (newreq);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
636 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
637
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
638
16
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
639 static gint
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
640 gftp_file_sort_function_as (gconstpointer a, gconstpointer b)
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
641 {
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
642 const gftp_file * f1, * f2;
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
643
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
644 f1 = a;
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
645 f2 = b;
535
8d310e2fd570 2004-8-17 Brian Masney <masneyb@gftp.org>
masneyb
parents: 532
diff changeset
646 return (strcasecmp (f1->file, f2->file));
16
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
647 }
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
648
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
649
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
650 static gint
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
651 gftp_file_sort_function_ds (gconstpointer a, gconstpointer b)
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
652 {
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
653 const gftp_file * f1, * f2;
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
654 gint ret;
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
655
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
656 f1 = a;
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
657 f2 = b;
535
8d310e2fd570 2004-8-17 Brian Masney <masneyb@gftp.org>
masneyb
parents: 532
diff changeset
658 ret = strcasecmp (f1->file, f2->file);
84
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 80
diff changeset
659 return (ret * -1);
16
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
660 }
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
661
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
662
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
663 static gint
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
664 gftp_user_sort_function_as (gconstpointer a, gconstpointer b)
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
665 {
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
666 const gftp_file * f1, * f2;
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
667
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
668 f1 = a;
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
669 f2 = b;
535
8d310e2fd570 2004-8-17 Brian Masney <masneyb@gftp.org>
masneyb
parents: 532
diff changeset
670 return (strcasecmp (f1->user, f2->user));
16
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
671 }
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
672
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
673
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
674 static gint
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
675 gftp_user_sort_function_ds (gconstpointer a, gconstpointer b)
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
676 {
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
677 const gftp_file * f1, * f2;
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
678 gint ret;
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
679
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
680 f1 = a;
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
681 f2 = b;
535
8d310e2fd570 2004-8-17 Brian Masney <masneyb@gftp.org>
masneyb
parents: 532
diff changeset
682 ret = strcasecmp (f1->user, f2->user);
84
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 80
diff changeset
683 return (ret * -1);
16
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
684 }
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
685
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
686
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
687 static gint
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
688 gftp_group_sort_function_as (gconstpointer a, gconstpointer b)
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
689 {
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
690 const gftp_file * f1, * f2;
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
691
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
692 f1 = a;
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
693 f2 = b;
535
8d310e2fd570 2004-8-17 Brian Masney <masneyb@gftp.org>
masneyb
parents: 532
diff changeset
694 return (strcasecmp (f1->group, f2->group));
16
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
695 }
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
696
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
697
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
698 static gint
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
699 gftp_group_sort_function_ds (gconstpointer a, gconstpointer b)
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
700 {
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
701 const gftp_file * f1, * f2;
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
702 gint ret;
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
703
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
704 f1 = a;
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
705 f2 = b;
535
8d310e2fd570 2004-8-17 Brian Masney <masneyb@gftp.org>
masneyb
parents: 532
diff changeset
706 ret = strcasecmp (f1->group, f2->group);
84
7ef60ce2bdb2 2002-12-29 Brian Masney <masneyb@gftp.org>
masneyb
parents: 80
diff changeset
707 return (ret * -1);
16
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
708 }
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
709
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
710
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
711 static gint
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
712 gftp_attribs_sort_function_as (gconstpointer a, gconstpointer b)
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
713 {
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
714 const gftp_file * f1, * f2;
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
715
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
716 f1 = a;
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
717 f2 = b;
499
39e9945288ea 2004-7-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 483
diff changeset
718 if (f1->st_mode < f2->st_mode)
39e9945288ea 2004-7-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 483
diff changeset
719 return (-1);
39e9945288ea 2004-7-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 483
diff changeset
720 else if (f1->st_mode == f2->st_mode)
39e9945288ea 2004-7-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 483
diff changeset
721 return (0);
39e9945288ea 2004-7-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 483
diff changeset
722 else
39e9945288ea 2004-7-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 483
diff changeset
723 return (1);
16
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
724 }
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
725
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
726
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
727 static gint
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
728 gftp_attribs_sort_function_ds (gconstpointer a, gconstpointer b)
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
729 {
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
730 const gftp_file * f1, * f2;
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
731
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
732 f1 = a;
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
733 f2 = b;
499
39e9945288ea 2004-7-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 483
diff changeset
734 if (f1->st_mode < f2->st_mode)
39e9945288ea 2004-7-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 483
diff changeset
735 return (1);
39e9945288ea 2004-7-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 483
diff changeset
736 else if (f1->st_mode == f2->st_mode)
39e9945288ea 2004-7-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 483
diff changeset
737 return (0);
39e9945288ea 2004-7-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 483
diff changeset
738 else
39e9945288ea 2004-7-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 483
diff changeset
739 return (-1);
16
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
740 }
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
741
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
742
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
743 static gint
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
744 gftp_size_sort_function_as (gconstpointer a, gconstpointer b)
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
745 {
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
746 const gftp_file * f1, * f2;
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
747
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
748 f1 = a;
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
749 f2 = b;
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
750 if (f1->size < f2->size)
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
751 return (-1);
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
752 else if (f1->size == f2->size)
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
753 return (0);
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
754 else
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
755 return (1);
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
756 }
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
757
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
758
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
759 static gint
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
760 gftp_size_sort_function_ds (gconstpointer a, gconstpointer b)
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
761 {
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
762 const gftp_file * f1, * f2;
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
763
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
764 f1 = a;
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
765 f2 = b;
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
766 if (f1->size < f2->size)
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
767 return (1);
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
768 else if (f1->size == f2->size)
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
769 return (0);
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
770 else
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
771 return (-1);
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
772 }
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
773
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
774
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
775 static gint
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
776 gftp_datetime_sort_function_as (gconstpointer a, gconstpointer b)
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
777 {
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
778 const gftp_file * f1, * f2;
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
779
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
780 f1 = a;
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
781 f2 = b;
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
782 if (f1->datetime < f2->datetime)
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
783 return (-1);
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
784 else if (f1->datetime == f2->datetime)
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
785 return (0);
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
786 else
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
787 return (1);
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
788 }
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
789
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
790
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
791 static gint
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
792 gftp_datetime_sort_function_ds (gconstpointer a, gconstpointer b)
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
793 {
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
794 const gftp_file * f1, * f2;
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
795
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
796 f1 = a;
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
797 f2 = b;
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
798 if (f1->datetime < f2->datetime)
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
799 return (1);
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
800 else if (f1->datetime == f2->datetime)
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
801 return (0);
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
802 else
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
803 return (-1);
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
804 }
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
805
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
806
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
807 GList *
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
808 gftp_sort_filelist (GList * filelist, int column, int asds)
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
809 {
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
810 GList * files, * dirs, * dotdot, * tempitem, * insitem;
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
811 GCompareFunc sortfunc;
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
812 gftp_file * tempfle;
325
0fcc6468a0af 2003-12-4 Brian Masney <masneyb@gftp.org>
masneyb
parents: 320
diff changeset
813 intptr_t sort_dirs_first;
16
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
814
422
38bfc112ab46 2004-3-14 Brian Masney <masneyb@gftp.org>
masneyb
parents: 378
diff changeset
815 if (filelist == NULL) /* nothing to sort */
38bfc112ab46 2004-3-14 Brian Masney <masneyb@gftp.org>
masneyb
parents: 378
diff changeset
816 return (filelist);
38bfc112ab46 2004-3-14 Brian Masney <masneyb@gftp.org>
masneyb
parents: 378
diff changeset
817
16
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
818 files = dirs = dotdot = NULL;
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
819
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
820 if (column == GFTP_SORT_COL_FILE)
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
821 sortfunc = asds ? gftp_file_sort_function_as : gftp_file_sort_function_ds;
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
822 else if (column == GFTP_SORT_COL_SIZE)
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
823 sortfunc = asds ? gftp_size_sort_function_as : gftp_size_sort_function_ds;
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
824 else if (column == GFTP_SORT_COL_USER)
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
825 sortfunc = asds ? gftp_user_sort_function_as : gftp_user_sort_function_ds;
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
826 else if (column == GFTP_SORT_COL_GROUP)
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
827 sortfunc = asds ?
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
828 gftp_group_sort_function_as : gftp_group_sort_function_ds;
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
829 else if (column == GFTP_SORT_COL_DATETIME)
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
830 sortfunc = asds ?
122
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 102
diff changeset
831 gftp_datetime_sort_function_as : gftp_datetime_sort_function_ds;
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 102
diff changeset
832 else if (column == GFTP_SORT_COL_ATTRIBS)
16
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
833 sortfunc = asds ?
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
834 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
835 else /* Don't sort */
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 102
diff changeset
836 return (filelist);
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 102
diff changeset
837
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 102
diff changeset
838 sort_dirs_first = 1;
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 102
diff changeset
839 gftp_lookup_global_option ("sort_dirs_first", &sort_dirs_first);
16
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
840
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
841 for (tempitem = filelist; tempitem != NULL; )
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
842 {
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
843 tempfle = tempitem->data;
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
844 insitem = tempitem;
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
845 tempitem = tempitem->next;
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
846 insitem->next = NULL;
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
847
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
848 if (dotdot == NULL && strcmp (tempfle->file, "..") == 0)
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
849 dotdot = insitem;
499
39e9945288ea 2004-7-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 483
diff changeset
850 else if (sort_dirs_first && S_ISDIR (tempfle->st_mode))
16
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
851 {
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
852 insitem->next = dirs;
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
853 dirs = insitem;
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
854 }
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
855 else
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
856 {
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
857 insitem->next = files;
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
858 files = insitem;
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
859 }
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
860 }
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
861
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
862 if (dirs != NULL)
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
863 dirs = g_list_sort (dirs, sortfunc);
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
864 if (files != NULL)
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
865 files = g_list_sort (files, sortfunc);
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
866
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
867 filelist = dotdot;
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
868
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
869 if (filelist == NULL)
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
870 filelist = dirs;
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
871 else
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
872 filelist = g_list_concat (filelist, dirs);
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
873
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
874 if (filelist == NULL)
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
875 filelist = files;
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
876 else
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
877 filelist = g_list_concat (filelist, files);
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
878
39
474d562c7268 2002-10-15 Brian Masney <masneyb@gftp.org>
masneyb
parents: 33
diff changeset
879 /* 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
880 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
881 filelist->prev = NULL;
16
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
882 return (filelist);
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
883 }
ddb983d8574b * Improved directory sorting algorithm
masneyb
parents: 14
diff changeset
884
125
b875de05c22d 2003-4-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
885
131
c77f85763e28 2003-4-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 129
diff changeset
886 char *
830
afbe37351940 2006-10-19 Brian Masney <masneyb@gftp.org>
masneyb
parents: 821
diff changeset
887 gftp_gen_ls_string (gftp_request * request, gftp_file * fle,
afbe37351940 2006-10-19 Brian Masney <masneyb@gftp.org>
masneyb
parents: 821
diff changeset
888 char *file_prefixstr, char *file_suffixstr)
131
c77f85763e28 2003-4-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 129
diff changeset
889 {
830
afbe37351940 2006-10-19 Brian Masney <masneyb@gftp.org>
masneyb
parents: 821
diff changeset
890 char *tempstr1, *tempstr2, *ret, tstr[50], *attribs, *utf8;
838
57aad6d4b304 2006-10-31 Brian Masney <masneyb@gftp.org>
masneyb
parents: 830
diff changeset
891 size_t destlen;
131
c77f85763e28 2003-4-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 129
diff changeset
892 struct tm *lt;
c77f85763e28 2003-4-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 129
diff changeset
893 time_t t;
c77f85763e28 2003-4-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 129
diff changeset
894
c77f85763e28 2003-4-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 129
diff changeset
895 lt = localtime (&fle->datetime);
c77f85763e28 2003-4-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 129
diff changeset
896
499
39e9945288ea 2004-7-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 483
diff changeset
897 attribs = gftp_convert_attributes_from_mode_t (fle->st_mode);
39e9945288ea 2004-7-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 483
diff changeset
898 tempstr1 = g_strdup_printf ("%10s %8s %8s", attribs, fle->user, fle->group);
39e9945288ea 2004-7-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 483
diff changeset
899 g_free (attribs);
131
c77f85763e28 2003-4-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 129
diff changeset
900
499
39e9945288ea 2004-7-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 483
diff changeset
901 if (GFTP_IS_SPECIAL_DEVICE (fle->st_mode))
131
c77f85763e28 2003-4-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 129
diff changeset
902 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
903 else
532
bccfdbfaac00 2004-8-17 Brian Masney <masneyb@gftp.org>
masneyb
parents: 516
diff changeset
904 tempstr2 = g_strdup_printf (GFTP_OFF_T_11PRINTF_MOD, fle->size);
131
c77f85763e28 2003-4-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 129
diff changeset
905
c77f85763e28 2003-4-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 129
diff changeset
906 time (&t);
c77f85763e28 2003-4-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 129
diff changeset
907
c77f85763e28 2003-4-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 129
diff changeset
908 if (fle->datetime > t || t - 3600*24*90 > fle->datetime)
c77f85763e28 2003-4-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 129
diff changeset
909 strftime (tstr, sizeof (tstr), "%b %d %Y", lt);
c77f85763e28 2003-4-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 129
diff changeset
910 else
c77f85763e28 2003-4-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 129
diff changeset
911 strftime (tstr, sizeof (tstr), "%b %d %H:%M", lt);
c77f85763e28 2003-4-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 129
diff changeset
912
c77f85763e28 2003-4-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 129
diff changeset
913 if (file_prefixstr == NULL)
c77f85763e28 2003-4-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 129
diff changeset
914 file_prefixstr = "";
c77f85763e28 2003-4-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 129
diff changeset
915 if (file_suffixstr == NULL)
c77f85763e28 2003-4-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 129
diff changeset
916 file_suffixstr = "";
c77f85763e28 2003-4-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 129
diff changeset
917
845
8263cc35c027 2006-11-2 Brian Masney <masneyb@gftp.org>
masneyb
parents: 843
diff changeset
918 utf8 = gftp_string_from_utf8 (request, 1, fle->file, &destlen);
843
32dbed7e0dc4 2006-11-2 Brian Masney <masneyb@gftp.org>
masneyb
parents: 838
diff changeset
919 if (utf8 != NULL)
32dbed7e0dc4 2006-11-2 Brian Masney <masneyb@gftp.org>
masneyb
parents: 838
diff changeset
920 {
32dbed7e0dc4 2006-11-2 Brian Masney <masneyb@gftp.org>
masneyb
parents: 838
diff changeset
921 ret = g_strdup_printf ("%s %s %s %s%s%s", tempstr1, tempstr2, tstr,
32dbed7e0dc4 2006-11-2 Brian Masney <masneyb@gftp.org>
masneyb
parents: 838
diff changeset
922 file_prefixstr, utf8, file_suffixstr);
32dbed7e0dc4 2006-11-2 Brian Masney <masneyb@gftp.org>
masneyb
parents: 838
diff changeset
923 g_free (utf8);
32dbed7e0dc4 2006-11-2 Brian Masney <masneyb@gftp.org>
masneyb
parents: 838
diff changeset
924 }
32dbed7e0dc4 2006-11-2 Brian Masney <masneyb@gftp.org>
masneyb
parents: 838
diff changeset
925 else
32dbed7e0dc4 2006-11-2 Brian Masney <masneyb@gftp.org>
masneyb
parents: 838
diff changeset
926 ret = g_strdup_printf ("%s %s %s %s%s%s", tempstr1, tempstr2, tstr,
32dbed7e0dc4 2006-11-2 Brian Masney <masneyb@gftp.org>
masneyb
parents: 838
diff changeset
927 file_prefixstr, fle->file, file_suffixstr);
131
c77f85763e28 2003-4-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 129
diff changeset
928
c77f85763e28 2003-4-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 129
diff changeset
929 g_free (tempstr1);
c77f85763e28 2003-4-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 129
diff changeset
930 g_free (tempstr2);
c77f85763e28 2003-4-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 129
diff changeset
931
c77f85763e28 2003-4-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 129
diff changeset
932 return (ret);
c77f85763e28 2003-4-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 129
diff changeset
933 }
c77f85763e28 2003-4-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 129
diff changeset
934
c77f85763e28 2003-4-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 129
diff changeset
935
125
b875de05c22d 2003-4-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
936 #if !defined (HAVE_GETADDRINFO) || !defined (HAVE_GAI_STRERROR)
b875de05c22d 2003-4-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
937
b875de05c22d 2003-4-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
938 struct hostent *
b875de05c22d 2003-4-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
939 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
940 {
b875de05c22d 2003-4-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
941 static GStaticMutex hostfunclock = G_STATIC_MUTEX_INIT;
b875de05c22d 2003-4-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
942 struct hostent *hent;
b875de05c22d 2003-4-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
943
b875de05c22d 2003-4-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
944 if (g_thread_supported ())
b875de05c22d 2003-4-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
945 g_static_mutex_lock (&hostfunclock);
b875de05c22d 2003-4-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
946
b875de05c22d 2003-4-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
947 if ((hent = gethostbyname (name)) == NULL)
b875de05c22d 2003-4-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
948 {
b875de05c22d 2003-4-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
949 if (h_errnop)
b875de05c22d 2003-4-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
950 *h_errnop = h_errno;
b875de05c22d 2003-4-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
951 }
b875de05c22d 2003-4-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
952 else
b875de05c22d 2003-4-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
953 {
b875de05c22d 2003-4-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
954 *result_buf = *hent;
b875de05c22d 2003-4-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
955 hent = result_buf;
b875de05c22d 2003-4-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
956 }
b875de05c22d 2003-4-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
957
b875de05c22d 2003-4-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
958 if (g_thread_supported ())
b875de05c22d 2003-4-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
959 g_static_mutex_unlock (&hostfunclock);
b875de05c22d 2003-4-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
960
b875de05c22d 2003-4-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
961 return (hent);
b875de05c22d 2003-4-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
962 }
b875de05c22d 2003-4-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
963
b875de05c22d 2003-4-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
964 #endif /* !HAVE_GETADDRINFO */
b875de05c22d 2003-4-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
965
b875de05c22d 2003-4-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
966 struct servent *
b875de05c22d 2003-4-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
967 r_getservbyname (const char *name, const char *proto,
b875de05c22d 2003-4-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
968 struct servent *result_buf, int *h_errnop)
b875de05c22d 2003-4-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
969 {
b875de05c22d 2003-4-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
970 static GStaticMutex servfunclock = G_STATIC_MUTEX_INIT;
b875de05c22d 2003-4-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
971 struct servent *sent;
b875de05c22d 2003-4-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
972
b875de05c22d 2003-4-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
973 if (g_thread_supported ())
b875de05c22d 2003-4-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
974 g_static_mutex_lock (&servfunclock);
b875de05c22d 2003-4-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
975
b875de05c22d 2003-4-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
976 if ((sent = getservbyname (name, proto)) == NULL)
b875de05c22d 2003-4-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
977 {
b875de05c22d 2003-4-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
978 if (h_errnop)
b875de05c22d 2003-4-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
979 *h_errnop = h_errno;
b875de05c22d 2003-4-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
980 }
b875de05c22d 2003-4-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
981 else
b875de05c22d 2003-4-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
982 {
b875de05c22d 2003-4-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
983 *result_buf = *sent;
b875de05c22d 2003-4-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
984 sent = result_buf;
b875de05c22d 2003-4-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
985 }
b875de05c22d 2003-4-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
986
b875de05c22d 2003-4-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
987 if (g_thread_supported ())
b875de05c22d 2003-4-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
988 g_static_mutex_unlock (&servfunclock);
b875de05c22d 2003-4-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
989 return (sent);
b875de05c22d 2003-4-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
990 }
b875de05c22d 2003-4-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 124
diff changeset
991
168
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 162
diff changeset
992
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 162
diff changeset
993 char *
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 162
diff changeset
994 base64_encode (char *str)
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 162
diff changeset
995 {
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 162
diff changeset
996
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 162
diff changeset
997 /* The standard to Base64 encoding can be found in RFC2045 */
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 162
diff changeset
998
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 162
diff changeset
999 char *newstr, *newpos, *fillpos, *pos;
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 162
diff changeset
1000 unsigned char table[64], encode[3];
460
075f89b4395c 2004-4-14 Brian Masney <masneyb@gftp.org>
masneyb
parents: 451
diff changeset
1001 size_t slen, num;
075f89b4395c 2004-4-14 Brian Masney <masneyb@gftp.org>
masneyb
parents: 451
diff changeset
1002 int i;
168
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 162
diff changeset
1003
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 162
diff changeset
1004 for (i = 0; i < 26; i++)
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 162
diff changeset
1005 {
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 162
diff changeset
1006 table[i] = 'A' + i;
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 162
diff changeset
1007 table[i + 26] = 'a' + i;
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 162
diff changeset
1008 }
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 162
diff changeset
1009
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 162
diff changeset
1010 for (i = 0; i < 10; i++)
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 162
diff changeset
1011 table[i + 52] = '0' + i;
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 162
diff changeset
1012
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 162
diff changeset
1013 table[62] = '+';
207
cf4098008615 2003-7-1 Brian Masney <masneyb@gftp.org>
masneyb
parents: 204
diff changeset
1014 table[63] = '/';
168
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 162
diff changeset
1015
460
075f89b4395c 2004-4-14 Brian Masney <masneyb@gftp.org>
masneyb
parents: 451
diff changeset
1016 slen = strlen (str);
075f89b4395c 2004-4-14 Brian Masney <masneyb@gftp.org>
masneyb
parents: 451
diff changeset
1017 num = slen / 3;
075f89b4395c 2004-4-14 Brian Masney <masneyb@gftp.org>
masneyb
parents: 451
diff changeset
1018 if (slen % 3 > 0)
168
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 162
diff changeset
1019 num++;
460
075f89b4395c 2004-4-14 Brian Masney <masneyb@gftp.org>
masneyb
parents: 451
diff changeset
1020
765
d553d14a2565 2006-7-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 682
diff changeset
1021 newstr = g_malloc ((gulong) num * 4 + 1);
168
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 162
diff changeset
1022 newstr[num * 4] = '\0';
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 162
diff changeset
1023 newpos = newstr;
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 162
diff changeset
1024
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 162
diff changeset
1025 pos = str;
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 162
diff changeset
1026 while (*pos != '\0')
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 162
diff changeset
1027 {
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 162
diff changeset
1028 memset (encode, 0, sizeof (encode));
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 162
diff changeset
1029 for (i = 0; i < 3 && *pos != '\0'; i++)
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 162
diff changeset
1030 encode[i] = *pos++;
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 162
diff changeset
1031
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 162
diff changeset
1032 fillpos = newpos;
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 162
diff changeset
1033 *newpos++ = table[encode[0] >> 2];
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 162
diff changeset
1034 *newpos++ = table[(encode[0] & 3) << 4 | encode[1] >> 4];
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 162
diff changeset
1035 *newpos++ = table[(encode[1] & 0xF) << 2 | encode[2] >> 6];
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 162
diff changeset
1036 *newpos++ = table[encode[2] & 0x3F];
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 162
diff changeset
1037 while (i < 3)
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 162
diff changeset
1038 fillpos[++i] = '=';
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 162
diff changeset
1039 }
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 162
diff changeset
1040 return (newstr);
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 162
diff changeset
1041 }
c505d9ba9d53 2003-6-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 162
diff changeset
1042
199
75eebb3b0592 2003-6-24 Brian Masney <masneyb@gftp.org>
masneyb
parents: 184
diff changeset
1043
75eebb3b0592 2003-6-24 Brian Masney <masneyb@gftp.org>
masneyb
parents: 184
diff changeset
1044 void
609
d97e985f5dbe 2004-11-3 Brian Masney <masneyb@gftp.org>
masneyb
parents: 598
diff changeset
1045 gftp_free_bookmark (gftp_bookmarks_var * entry, int free_node)
199
75eebb3b0592 2003-6-24 Brian Masney <masneyb@gftp.org>
masneyb
parents: 184
diff changeset
1046 {
609
d97e985f5dbe 2004-11-3 Brian Masney <masneyb@gftp.org>
masneyb
parents: 598
diff changeset
1047 gftp_bookmarks_var * tempentry;
d97e985f5dbe 2004-11-3 Brian Masney <masneyb@gftp.org>
masneyb
parents: 598
diff changeset
1048
612
08e7b5186eb8 2004-11-4 Brian Masney <masneyb@gftp.org>
masneyb
parents: 609
diff changeset
1049 if (entry->path)
08e7b5186eb8 2004-11-4 Brian Masney <masneyb@gftp.org>
masneyb
parents: 609
diff changeset
1050 g_free (entry->path);
08e7b5186eb8 2004-11-4 Brian Masney <masneyb@gftp.org>
masneyb
parents: 609
diff changeset
1051 if (entry->oldpath)
08e7b5186eb8 2004-11-4 Brian Masney <masneyb@gftp.org>
masneyb
parents: 609
diff changeset
1052 g_free (entry->oldpath);
199
75eebb3b0592 2003-6-24 Brian Masney <masneyb@gftp.org>
masneyb
parents: 184
diff changeset
1053 if (entry->hostname)
75eebb3b0592 2003-6-24 Brian Masney <masneyb@gftp.org>
masneyb
parents: 184
diff changeset
1054 g_free (entry->hostname);
75eebb3b0592 2003-6-24 Brian Masney <masneyb@gftp.org>
masneyb
parents: 184
diff changeset
1055 if (entry->remote_dir)
75eebb3b0592 2003-6-24 Brian Masney <masneyb@gftp.org>
masneyb
parents: 184
diff changeset
1056 g_free (entry->remote_dir);
75eebb3b0592 2003-6-24 Brian Masney <masneyb@gftp.org>
masneyb
parents: 184
diff changeset
1057 if (entry->local_dir)
75eebb3b0592 2003-6-24 Brian Masney <masneyb@gftp.org>
masneyb
parents: 184
diff changeset
1058 g_free (entry->local_dir);
75eebb3b0592 2003-6-24 Brian Masney <masneyb@gftp.org>
masneyb
parents: 184
diff changeset
1059 if (entry->user)
75eebb3b0592 2003-6-24 Brian Masney <masneyb@gftp.org>
masneyb
parents: 184
diff changeset
1060 g_free (entry->user);
75eebb3b0592 2003-6-24 Brian Masney <masneyb@gftp.org>
masneyb
parents: 184
diff changeset
1061 if (entry->pass)
75eebb3b0592 2003-6-24 Brian Masney <masneyb@gftp.org>
masneyb
parents: 184
diff changeset
1062 g_free (entry->pass);
75eebb3b0592 2003-6-24 Brian Masney <masneyb@gftp.org>
masneyb
parents: 184
diff changeset
1063 if (entry->acct)
75eebb3b0592 2003-6-24 Brian Masney <masneyb@gftp.org>
masneyb
parents: 184
diff changeset
1064 g_free (entry->acct);
75eebb3b0592 2003-6-24 Brian Masney <masneyb@gftp.org>
masneyb
parents: 184
diff changeset
1065 if (entry->protocol)
75eebb3b0592 2003-6-24 Brian Masney <masneyb@gftp.org>
masneyb
parents: 184
diff changeset
1066 g_free (entry->protocol);
75eebb3b0592 2003-6-24 Brian Masney <masneyb@gftp.org>
masneyb
parents: 184
diff changeset
1067
75eebb3b0592 2003-6-24 Brian Masney <masneyb@gftp.org>
masneyb
parents: 184
diff changeset
1068 if (entry->local_options_vars != NULL)
75eebb3b0592 2003-6-24 Brian Masney <masneyb@gftp.org>
masneyb
parents: 184
diff changeset
1069 {
201
0098dae654a5 2003-6-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 199
diff changeset
1070 gftp_config_free_options (entry->local_options_vars,
0098dae654a5 2003-6-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 199
diff changeset
1071 entry->local_options_hash,
0098dae654a5 2003-6-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 199
diff changeset
1072 entry->num_local_options_vars);
0098dae654a5 2003-6-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 199
diff changeset
1073
199
75eebb3b0592 2003-6-24 Brian Masney <masneyb@gftp.org>
masneyb
parents: 184
diff changeset
1074 entry->local_options_vars = NULL;
201
0098dae654a5 2003-6-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 199
diff changeset
1075 entry->local_options_hash = NULL;
199
75eebb3b0592 2003-6-24 Brian Masney <masneyb@gftp.org>
masneyb
parents: 184
diff changeset
1076 entry->num_local_options_vars = 0;
75eebb3b0592 2003-6-24 Brian Masney <masneyb@gftp.org>
masneyb
parents: 184
diff changeset
1077 }
609
d97e985f5dbe 2004-11-3 Brian Masney <masneyb@gftp.org>
masneyb
parents: 598
diff changeset
1078
d97e985f5dbe 2004-11-3 Brian Masney <masneyb@gftp.org>
masneyb
parents: 598
diff changeset
1079 if (free_node)
d97e985f5dbe 2004-11-3 Brian Masney <masneyb@gftp.org>
masneyb
parents: 598
diff changeset
1080 g_free (entry);
d97e985f5dbe 2004-11-3 Brian Masney <masneyb@gftp.org>
masneyb
parents: 598
diff changeset
1081 else
d97e985f5dbe 2004-11-3 Brian Masney <masneyb@gftp.org>
masneyb
parents: 598
diff changeset
1082 {
d97e985f5dbe 2004-11-3 Brian Masney <masneyb@gftp.org>
masneyb
parents: 598
diff changeset
1083 tempentry = entry->children;
d97e985f5dbe 2004-11-3 Brian Masney <masneyb@gftp.org>
masneyb
parents: 598
diff changeset
1084 memset (entry, 0, sizeof (*entry));
d97e985f5dbe 2004-11-3 Brian Masney <masneyb@gftp.org>
masneyb
parents: 598
diff changeset
1085 entry->children = tempentry;
d97e985f5dbe 2004-11-3 Brian Masney <masneyb@gftp.org>
masneyb
parents: 598
diff changeset
1086 }
199
75eebb3b0592 2003-6-24 Brian Masney <masneyb@gftp.org>
masneyb
parents: 184
diff changeset
1087 }
75eebb3b0592 2003-6-24 Brian Masney <masneyb@gftp.org>
masneyb
parents: 184
diff changeset
1088
201
0098dae654a5 2003-6-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 199
diff changeset
1089
0098dae654a5 2003-6-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 199
diff changeset
1090 void
0098dae654a5 2003-6-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 199
diff changeset
1091 gftp_shutdown (void)
0098dae654a5 2003-6-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 199
diff changeset
1092 {
203
95e669973a84 2003-6-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 201
diff changeset
1093 #ifdef WITH_DMALLOC
201
0098dae654a5 2003-6-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 199
diff changeset
1094 gftp_config_vars * cv;
0098dae654a5 2003-6-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 199
diff changeset
1095 GList * templist;
203
95e669973a84 2003-6-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 201
diff changeset
1096 #endif
201
0098dae654a5 2003-6-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 199
diff changeset
1097
0098dae654a5 2003-6-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 199
diff changeset
1098 if (gftp_logfd != NULL)
0098dae654a5 2003-6-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 199
diff changeset
1099 fclose (gftp_logfd);
0098dae654a5 2003-6-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 199
diff changeset
1100
0098dae654a5 2003-6-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 199
diff changeset
1101 gftp_clear_cache_files ();
0098dae654a5 2003-6-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 199
diff changeset
1102
0098dae654a5 2003-6-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 199
diff changeset
1103 if (gftp_configuration_changed)
0098dae654a5 2003-6-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 199
diff changeset
1104 gftp_write_config_file ();
0098dae654a5 2003-6-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 199
diff changeset
1105
0098dae654a5 2003-6-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 199
diff changeset
1106 #ifdef WITH_DMALLOC
0098dae654a5 2003-6-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 199
diff changeset
1107 if (gftp_global_options_htable != NULL)
0098dae654a5 2003-6-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 199
diff changeset
1108 g_hash_table_destroy (gftp_global_options_htable);
0098dae654a5 2003-6-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 199
diff changeset
1109
0098dae654a5 2003-6-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 199
diff changeset
1110 if (gftp_config_list_htable != NULL)
0098dae654a5 2003-6-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 199
diff changeset
1111 g_hash_table_destroy (gftp_config_list_htable);
0098dae654a5 2003-6-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 199
diff changeset
1112
0098dae654a5 2003-6-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 199
diff changeset
1113 if (gftp_bookmarks_htable != NULL)
0098dae654a5 2003-6-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 199
diff changeset
1114 g_hash_table_destroy (gftp_bookmarks_htable);
0098dae654a5 2003-6-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 199
diff changeset
1115
0098dae654a5 2003-6-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 199
diff changeset
1116 for (templist = gftp_options_list;
0098dae654a5 2003-6-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 199
diff changeset
1117 templist != NULL;
0098dae654a5 2003-6-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 199
diff changeset
1118 templist = templist->next)
0098dae654a5 2003-6-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 199
diff changeset
1119 {
0098dae654a5 2003-6-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 199
diff changeset
1120 cv = templist->data;
0098dae654a5 2003-6-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 199
diff changeset
1121 gftp_config_free_options (cv, NULL, -1);
0098dae654a5 2003-6-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 199
diff changeset
1122 }
0098dae654a5 2003-6-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 199
diff changeset
1123
0098dae654a5 2003-6-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 199
diff changeset
1124 gftp_bookmarks_destroy (gftp_bookmarks);
0098dae654a5 2003-6-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 199
diff changeset
1125
0098dae654a5 2003-6-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 199
diff changeset
1126 dmalloc_shutdown ();
0098dae654a5 2003-6-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 199
diff changeset
1127 #endif
0098dae654a5 2003-6-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 199
diff changeset
1128
0098dae654a5 2003-6-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 199
diff changeset
1129 exit (0);
0098dae654a5 2003-6-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 199
diff changeset
1130 }
0098dae654a5 2003-6-25 Brian Masney <masneyb@gftp.org>
masneyb
parents: 199
diff changeset
1131
207
cf4098008615 2003-7-1 Brian Masney <masneyb@gftp.org>
masneyb
parents: 204
diff changeset
1132
cf4098008615 2003-7-1 Brian Masney <masneyb@gftp.org>
masneyb
parents: 204
diff changeset
1133 GList *
cf4098008615 2003-7-1 Brian Masney <masneyb@gftp.org>
masneyb
parents: 204
diff changeset
1134 get_next_selection (GList * selection, GList ** list, int *curnum)
cf4098008615 2003-7-1 Brian Masney <masneyb@gftp.org>
masneyb
parents: 204
diff changeset
1135 {
cf4098008615 2003-7-1 Brian Masney <masneyb@gftp.org>
masneyb
parents: 204
diff changeset
1136 gftp_file * tempfle;
cf4098008615 2003-7-1 Brian Masney <masneyb@gftp.org>
masneyb
parents: 204
diff changeset
1137 int i, newpos;
cf4098008615 2003-7-1 Brian Masney <masneyb@gftp.org>
masneyb
parents: 204
diff changeset
1138
cf4098008615 2003-7-1 Brian Masney <masneyb@gftp.org>
masneyb
parents: 204
diff changeset
1139 newpos = GPOINTER_TO_INT (selection->data);
cf4098008615 2003-7-1 Brian Masney <masneyb@gftp.org>
masneyb
parents: 204
diff changeset
1140 i = *curnum - newpos;
cf4098008615 2003-7-1 Brian Masney <masneyb@gftp.org>
masneyb
parents: 204
diff changeset
1141
cf4098008615 2003-7-1 Brian Masney <masneyb@gftp.org>
masneyb
parents: 204
diff changeset
1142 if (i < 0)
cf4098008615 2003-7-1 Brian Masney <masneyb@gftp.org>
masneyb
parents: 204
diff changeset
1143 {
cf4098008615 2003-7-1 Brian Masney <masneyb@gftp.org>
masneyb
parents: 204
diff changeset
1144 while (i != 0)
cf4098008615 2003-7-1 Brian Masney <masneyb@gftp.org>
masneyb
parents: 204
diff changeset
1145 {
cf4098008615 2003-7-1 Brian Masney <masneyb@gftp.org>
masneyb
parents: 204
diff changeset
1146 tempfle = (*list)->data;
cf4098008615 2003-7-1 Brian Masney <masneyb@gftp.org>
masneyb
parents: 204
diff changeset
1147 if (tempfle->shown)
cf4098008615 2003-7-1 Brian Masney <masneyb@gftp.org>
masneyb
parents: 204
diff changeset
1148 {
cf4098008615 2003-7-1 Brian Masney <masneyb@gftp.org>
masneyb
parents: 204
diff changeset
1149 ++*curnum;
cf4098008615 2003-7-1 Brian Masney <masneyb@gftp.org>
masneyb
parents: 204
diff changeset
1150 i++;
cf4098008615 2003-7-1 Brian Masney <masneyb@gftp.org>
masneyb
parents: 204
diff changeset
1151 }
cf4098008615 2003-7-1 Brian Masney <masneyb@gftp.org>
masneyb
parents: 204
diff changeset
1152 *list = (*list)->next;
cf4098008615 2003-7-1 Brian Masney <masneyb@gftp.org>
masneyb
parents: 204
diff changeset
1153 }
cf4098008615 2003-7-1 Brian Masney <masneyb@gftp.org>
masneyb
parents: 204
diff changeset
1154 }
cf4098008615 2003-7-1 Brian Masney <masneyb@gftp.org>
masneyb
parents: 204
diff changeset
1155 else if (i > 0)
cf4098008615 2003-7-1 Brian Masney <masneyb@gftp.org>
masneyb
parents: 204
diff changeset
1156 {
cf4098008615 2003-7-1 Brian Masney <masneyb@gftp.org>
masneyb
parents: 204
diff changeset
1157 while (i != 0)
cf4098008615 2003-7-1 Brian Masney <masneyb@gftp.org>
masneyb
parents: 204
diff changeset
1158 {
cf4098008615 2003-7-1 Brian Masney <masneyb@gftp.org>
masneyb
parents: 204
diff changeset
1159 tempfle = (*list)->data;
cf4098008615 2003-7-1 Brian Masney <masneyb@gftp.org>
masneyb
parents: 204
diff changeset
1160 if (tempfle->shown)
cf4098008615 2003-7-1 Brian Masney <masneyb@gftp.org>
masneyb
parents: 204
diff changeset
1161 {
cf4098008615 2003-7-1 Brian Masney <masneyb@gftp.org>
masneyb
parents: 204
diff changeset
1162 --*curnum;
cf4098008615 2003-7-1 Brian Masney <masneyb@gftp.org>
masneyb
parents: 204
diff changeset
1163 i--;
cf4098008615 2003-7-1 Brian Masney <masneyb@gftp.org>
masneyb
parents: 204
diff changeset
1164 }
cf4098008615 2003-7-1 Brian Masney <masneyb@gftp.org>
masneyb
parents: 204
diff changeset
1165 *list = (*list)->prev;
cf4098008615 2003-7-1 Brian Masney <masneyb@gftp.org>
masneyb
parents: 204
diff changeset
1166 }
cf4098008615 2003-7-1 Brian Masney <masneyb@gftp.org>
masneyb
parents: 204
diff changeset
1167 }
cf4098008615 2003-7-1 Brian Masney <masneyb@gftp.org>
masneyb
parents: 204
diff changeset
1168
cf4098008615 2003-7-1 Brian Masney <masneyb@gftp.org>
masneyb
parents: 204
diff changeset
1169 tempfle = (*list)->data;
cf4098008615 2003-7-1 Brian Masney <masneyb@gftp.org>
masneyb
parents: 204
diff changeset
1170 while ((*list)->next && !tempfle->shown)
cf4098008615 2003-7-1 Brian Masney <masneyb@gftp.org>
masneyb
parents: 204
diff changeset
1171 {
cf4098008615 2003-7-1 Brian Masney <masneyb@gftp.org>
masneyb
parents: 204
diff changeset
1172 *list = (*list)->next;
cf4098008615 2003-7-1 Brian Masney <masneyb@gftp.org>
masneyb
parents: 204
diff changeset
1173 tempfle = (*list)->data;
cf4098008615 2003-7-1 Brian Masney <masneyb@gftp.org>
masneyb
parents: 204
diff changeset
1174 }
cf4098008615 2003-7-1 Brian Masney <masneyb@gftp.org>
masneyb
parents: 204
diff changeset
1175 return (selection->next);
cf4098008615 2003-7-1 Brian Masney <masneyb@gftp.org>
masneyb
parents: 204
diff changeset
1176 }
cf4098008615 2003-7-1 Brian Masney <masneyb@gftp.org>
masneyb
parents: 204
diff changeset
1177
cf4098008615 2003-7-1 Brian Masney <masneyb@gftp.org>
masneyb
parents: 204
diff changeset
1178
227
a85a097bbb02 2003-7-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 220
diff changeset
1179 char *
555
7f54d0c0edbc 2004-9-17 Brian Masney <masneyb@gftp.org>
masneyb
parents: 547
diff changeset
1180 gftp_build_path (gftp_request * request, const char *first_element, ...)
227
a85a097bbb02 2003-7-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 220
diff changeset
1181 {
a85a097bbb02 2003-7-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 220
diff changeset
1182 const char *element;
a85a097bbb02 2003-7-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 220
diff changeset
1183 size_t len, retlen;
a85a097bbb02 2003-7-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 220
diff changeset
1184 int add_separator;
a85a097bbb02 2003-7-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 220
diff changeset
1185 va_list args;
a85a097bbb02 2003-7-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 220
diff changeset
1186 char *ret;
a85a097bbb02 2003-7-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 220
diff changeset
1187
245
41af60bc1f88 2003-8-4 Brian Masney <masneyb@gftp.org>
masneyb
parents: 244
diff changeset
1188 g_return_val_if_fail (first_element != NULL, NULL);
227
a85a097bbb02 2003-7-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 220
diff changeset
1189
247
f41650dc896c 2003-8-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 245
diff changeset
1190 ret = g_strdup (first_element);
f41650dc896c 2003-8-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 245
diff changeset
1191 retlen = strlen (ret);
227
a85a097bbb02 2003-7-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 220
diff changeset
1192
a85a097bbb02 2003-7-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 220
diff changeset
1193 va_start (args, first_element);
247
f41650dc896c 2003-8-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 245
diff changeset
1194 for (element = va_arg (args, char *);
227
a85a097bbb02 2003-7-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 220
diff changeset
1195 element != NULL;
a85a097bbb02 2003-7-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 220
diff changeset
1196 element = va_arg (args, char *))
a85a097bbb02 2003-7-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 220
diff changeset
1197 {
a85a097bbb02 2003-7-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 220
diff changeset
1198 len = strlen (element);
a85a097bbb02 2003-7-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 220
diff changeset
1199
422
38bfc112ab46 2004-3-14 Brian Masney <masneyb@gftp.org>
masneyb
parents: 378
diff changeset
1200 if (len == 0)
38bfc112ab46 2004-3-14 Brian Masney <masneyb@gftp.org>
masneyb
parents: 378
diff changeset
1201 continue;
38bfc112ab46 2004-3-14 Brian Masney <masneyb@gftp.org>
masneyb
parents: 378
diff changeset
1202
369
c63208a1f0f1 2003-1-18 Brian Masney <masneyb@gftp.org>
masneyb
parents: 368
diff changeset
1203 if (retlen > 0 && (ret[retlen - 1] == '/' || element[0] == '/'))
227
a85a097bbb02 2003-7-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 220
diff changeset
1204 add_separator = 0;
a85a097bbb02 2003-7-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 220
diff changeset
1205 else
a85a097bbb02 2003-7-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 220
diff changeset
1206 {
a85a097bbb02 2003-7-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 220
diff changeset
1207 add_separator = 1;
a85a097bbb02 2003-7-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 220
diff changeset
1208 len++;
a85a097bbb02 2003-7-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 220
diff changeset
1209 }
a85a097bbb02 2003-7-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 220
diff changeset
1210
a85a097bbb02 2003-7-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 220
diff changeset
1211 retlen += len;
765
d553d14a2565 2006-7-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 682
diff changeset
1212 ret = g_realloc (ret, (gulong) retlen + 1);
227
a85a097bbb02 2003-7-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 220
diff changeset
1213
555
7f54d0c0edbc 2004-9-17 Brian Masney <masneyb@gftp.org>
masneyb
parents: 547
diff changeset
1214 /* Don't append a / for VMS servers... */
7f54d0c0edbc 2004-9-17 Brian Masney <masneyb@gftp.org>
masneyb
parents: 547
diff changeset
1215 if (add_separator &&
7f54d0c0edbc 2004-9-17 Brian Masney <masneyb@gftp.org>
masneyb
parents: 547
diff changeset
1216 (request == NULL || request->server_type != GFTP_DIRTYPE_VMS))
245
41af60bc1f88 2003-8-4 Brian Masney <masneyb@gftp.org>
masneyb
parents: 244
diff changeset
1217 strncat (ret, "/", retlen);
41af60bc1f88 2003-8-4 Brian Masney <masneyb@gftp.org>
masneyb
parents: 244
diff changeset
1218
41af60bc1f88 2003-8-4 Brian Masney <masneyb@gftp.org>
masneyb
parents: 244
diff changeset
1219 strncat (ret, element, retlen);
227
a85a097bbb02 2003-7-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 220
diff changeset
1220 }
a85a097bbb02 2003-7-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 220
diff changeset
1221
a85a097bbb02 2003-7-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 220
diff changeset
1222 return (ret);
a85a097bbb02 2003-7-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 220
diff changeset
1223 }
a85a097bbb02 2003-7-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 220
diff changeset
1224
244
afbbc72b73e2 2003-8-3 Brian Masney <masneyb@gftp.org>
masneyb
parents: 243
diff changeset
1225
290
6e255984c0b0 2003-10-18 Brian Masney <masneyb@gftp.org>
masneyb
parents: 289
diff changeset
1226 void
6e255984c0b0 2003-10-18 Brian Masney <masneyb@gftp.org>
masneyb
parents: 289
diff changeset
1227 gftp_locale_init (void)
6e255984c0b0 2003-10-18 Brian Masney <masneyb@gftp.org>
masneyb
parents: 289
diff changeset
1228 {
6e255984c0b0 2003-10-18 Brian Masney <masneyb@gftp.org>
masneyb
parents: 289
diff changeset
1229 #ifdef HAVE_GETTEXT
6e255984c0b0 2003-10-18 Brian Masney <masneyb@gftp.org>
masneyb
parents: 289
diff changeset
1230
6e255984c0b0 2003-10-18 Brian Masney <masneyb@gftp.org>
masneyb
parents: 289
diff changeset
1231 setlocale (LC_ALL, "");
6e255984c0b0 2003-10-18 Brian Masney <masneyb@gftp.org>
masneyb
parents: 289
diff changeset
1232 textdomain ("gftp");
320
853981bbd4d7 2003-11-30 Brian Masney <masneyb@gftp.org>
masneyb
parents: 309
diff changeset
1233 bindtextdomain ("gftp", LOCALE_DIR);
290
6e255984c0b0 2003-10-18 Brian Masney <masneyb@gftp.org>
masneyb
parents: 289
diff changeset
1234
6e255984c0b0 2003-10-18 Brian Masney <masneyb@gftp.org>
masneyb
parents: 289
diff changeset
1235 #if GLIB_MAJOR_VERSION > 1
6e255984c0b0 2003-10-18 Brian Masney <masneyb@gftp.org>
masneyb
parents: 289
diff changeset
1236 bind_textdomain_codeset ("gftp", "UTF-8");
6e255984c0b0 2003-10-18 Brian Masney <masneyb@gftp.org>
masneyb
parents: 289
diff changeset
1237 #endif
6e255984c0b0 2003-10-18 Brian Masney <masneyb@gftp.org>
masneyb
parents: 289
diff changeset
1238
320
853981bbd4d7 2003-11-30 Brian Masney <masneyb@gftp.org>
masneyb
parents: 309
diff changeset
1239 #endif /* HAVE_GETTEXT */
290
6e255984c0b0 2003-10-18 Brian Masney <masneyb@gftp.org>
masneyb
parents: 289
diff changeset
1240 }
6e255984c0b0 2003-10-18 Brian Masney <masneyb@gftp.org>
masneyb
parents: 289
diff changeset
1241
330
532eb171d5c2 2003-12-7 Brian Masney <masneyb@gftp.org>
masneyb
parents: 328
diff changeset
1242 /* Very primary encryption/decryption to make the passwords unreadable
532eb171d5c2 2003-12-7 Brian Masney <masneyb@gftp.org>
masneyb
parents: 328
diff changeset
1243 with 'cat ~/.gftp/bookmarks'.
532eb171d5c2 2003-12-7 Brian Masney <masneyb@gftp.org>
masneyb
parents: 328
diff changeset
1244
532eb171d5c2 2003-12-7 Brian Masney <masneyb@gftp.org>
masneyb
parents: 328
diff changeset
1245 Each character is separated in two nibbles. Then each nibble is stored
532eb171d5c2 2003-12-7 Brian Masney <masneyb@gftp.org>
masneyb
parents: 328
diff changeset
1246 under the form 01xxxx01. The resulted string is prefixed by a '$'.
532eb171d5c2 2003-12-7 Brian Masney <masneyb@gftp.org>
masneyb
parents: 328
diff changeset
1247 */
532eb171d5c2 2003-12-7 Brian Masney <masneyb@gftp.org>
masneyb
parents: 328
diff changeset
1248
532eb171d5c2 2003-12-7 Brian Masney <masneyb@gftp.org>
masneyb
parents: 328
diff changeset
1249
532eb171d5c2 2003-12-7 Brian Masney <masneyb@gftp.org>
masneyb
parents: 328
diff changeset
1250 char *
532eb171d5c2 2003-12-7 Brian Masney <masneyb@gftp.org>
masneyb
parents: 328
diff changeset
1251 gftp_scramble_password (const char *password)
532eb171d5c2 2003-12-7 Brian Masney <masneyb@gftp.org>
masneyb
parents: 328
diff changeset
1252 {
532eb171d5c2 2003-12-7 Brian Masney <masneyb@gftp.org>
masneyb
parents: 328
diff changeset
1253 char *newstr, *newpos;
532eb171d5c2 2003-12-7 Brian Masney <masneyb@gftp.org>
masneyb
parents: 328
diff changeset
1254
532eb171d5c2 2003-12-7 Brian Masney <masneyb@gftp.org>
masneyb
parents: 328
diff changeset
1255 if (strcmp (password, "@EMAIL@") == 0)
532eb171d5c2 2003-12-7 Brian Masney <masneyb@gftp.org>
masneyb
parents: 328
diff changeset
1256 return (g_strdup (password));
532eb171d5c2 2003-12-7 Brian Masney <masneyb@gftp.org>
masneyb
parents: 328
diff changeset
1257
765
d553d14a2565 2006-7-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 682
diff changeset
1258 newstr = g_malloc ((gulong) strlen (password) * 2 + 2);
330
532eb171d5c2 2003-12-7 Brian Masney <masneyb@gftp.org>
masneyb
parents: 328
diff changeset
1259 newpos = newstr;
532eb171d5c2 2003-12-7 Brian Masney <masneyb@gftp.org>
masneyb
parents: 328
diff changeset
1260
532eb171d5c2 2003-12-7 Brian Masney <masneyb@gftp.org>
masneyb
parents: 328
diff changeset
1261 *newpos++ = '$';
532eb171d5c2 2003-12-7 Brian Masney <masneyb@gftp.org>
masneyb
parents: 328
diff changeset
1262
765
d553d14a2565 2006-7-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 682
diff changeset
1263 while (*password != '\0')
330
532eb171d5c2 2003-12-7 Brian Masney <masneyb@gftp.org>
masneyb
parents: 328
diff changeset
1264 {
532eb171d5c2 2003-12-7 Brian Masney <masneyb@gftp.org>
masneyb
parents: 328
diff changeset
1265 *newpos++ = ((*password >> 2) & 0x3c) | 0x41;
532eb171d5c2 2003-12-7 Brian Masney <masneyb@gftp.org>
masneyb
parents: 328
diff changeset
1266 *newpos++ = ((*password << 2) & 0x3c) | 0x41;
532eb171d5c2 2003-12-7 Brian Masney <masneyb@gftp.org>
masneyb
parents: 328
diff changeset
1267 password++;
532eb171d5c2 2003-12-7 Brian Masney <masneyb@gftp.org>
masneyb
parents: 328
diff changeset
1268 }
532eb171d5c2 2003-12-7 Brian Masney <masneyb@gftp.org>
masneyb
parents: 328
diff changeset
1269 *newpos = 0;
532eb171d5c2 2003-12-7 Brian Masney <masneyb@gftp.org>
masneyb
parents: 328
diff changeset
1270
532eb171d5c2 2003-12-7 Brian Masney <masneyb@gftp.org>
masneyb
parents: 328
diff changeset
1271 return (newstr);
532eb171d5c2 2003-12-7 Brian Masney <masneyb@gftp.org>
masneyb
parents: 328
diff changeset
1272 }
532eb171d5c2 2003-12-7 Brian Masney <masneyb@gftp.org>
masneyb
parents: 328
diff changeset
1273
532eb171d5c2 2003-12-7 Brian Masney <masneyb@gftp.org>
masneyb
parents: 328
diff changeset
1274
532eb171d5c2 2003-12-7 Brian Masney <masneyb@gftp.org>
masneyb
parents: 328
diff changeset
1275 char *
532eb171d5c2 2003-12-7 Brian Masney <masneyb@gftp.org>
masneyb
parents: 328
diff changeset
1276 gftp_descramble_password (const char *password)
532eb171d5c2 2003-12-7 Brian Masney <masneyb@gftp.org>
masneyb
parents: 328
diff changeset
1277 {
532eb171d5c2 2003-12-7 Brian Masney <masneyb@gftp.org>
masneyb
parents: 328
diff changeset
1278 const char *passwordpos;
532eb171d5c2 2003-12-7 Brian Masney <masneyb@gftp.org>
masneyb
parents: 328
diff changeset
1279 char *newstr, *newpos;
532eb171d5c2 2003-12-7 Brian Masney <masneyb@gftp.org>
masneyb
parents: 328
diff changeset
1280 int error;
532eb171d5c2 2003-12-7 Brian Masney <masneyb@gftp.org>
masneyb
parents: 328
diff changeset
1281
532eb171d5c2 2003-12-7 Brian Masney <masneyb@gftp.org>
masneyb
parents: 328
diff changeset
1282 if (*password != '$')
532eb171d5c2 2003-12-7 Brian Masney <masneyb@gftp.org>
masneyb
parents: 328
diff changeset
1283 return (g_strdup (password));
532eb171d5c2 2003-12-7 Brian Masney <masneyb@gftp.org>
masneyb
parents: 328
diff changeset
1284
532eb171d5c2 2003-12-7 Brian Masney <masneyb@gftp.org>
masneyb
parents: 328
diff changeset
1285 passwordpos = password + 1;
765
d553d14a2565 2006-7-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 682
diff changeset
1286 newstr = g_malloc ((gulong) strlen (passwordpos) / 2 + 1);
330
532eb171d5c2 2003-12-7 Brian Masney <masneyb@gftp.org>
masneyb
parents: 328
diff changeset
1287 newpos = newstr;
532eb171d5c2 2003-12-7 Brian Masney <masneyb@gftp.org>
masneyb
parents: 328
diff changeset
1288
532eb171d5c2 2003-12-7 Brian Masney <masneyb@gftp.org>
masneyb
parents: 328
diff changeset
1289 error = 0;
765
d553d14a2565 2006-7-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 682
diff changeset
1290 while (*passwordpos != '\0' && *(passwordpos + 1) != '\0')
330
532eb171d5c2 2003-12-7 Brian Masney <masneyb@gftp.org>
masneyb
parents: 328
diff changeset
1291 {
532eb171d5c2 2003-12-7 Brian Masney <masneyb@gftp.org>
masneyb
parents: 328
diff changeset
1292 if ((*passwordpos & 0xc3) != 0x41 ||
532eb171d5c2 2003-12-7 Brian Masney <masneyb@gftp.org>
masneyb
parents: 328
diff changeset
1293 (*(passwordpos + 1) & 0xc3) != 0x41)
532eb171d5c2 2003-12-7 Brian Masney <masneyb@gftp.org>
masneyb
parents: 328
diff changeset
1294 {
532eb171d5c2 2003-12-7 Brian Masney <masneyb@gftp.org>
masneyb
parents: 328
diff changeset
1295 error = 1;
532eb171d5c2 2003-12-7 Brian Masney <masneyb@gftp.org>
masneyb
parents: 328
diff changeset
1296 break;
532eb171d5c2 2003-12-7 Brian Masney <masneyb@gftp.org>
masneyb
parents: 328
diff changeset
1297 }
532eb171d5c2 2003-12-7 Brian Masney <masneyb@gftp.org>
masneyb
parents: 328
diff changeset
1298
532eb171d5c2 2003-12-7 Brian Masney <masneyb@gftp.org>
masneyb
parents: 328
diff changeset
1299 *newpos++ = ((*passwordpos & 0x3c) << 2) |
532eb171d5c2 2003-12-7 Brian Masney <masneyb@gftp.org>
masneyb
parents: 328
diff changeset
1300 ((*(passwordpos + 1) & 0x3c) >> 2);
532eb171d5c2 2003-12-7 Brian Masney <masneyb@gftp.org>
masneyb
parents: 328
diff changeset
1301
532eb171d5c2 2003-12-7 Brian Masney <masneyb@gftp.org>
masneyb
parents: 328
diff changeset
1302 passwordpos += 2;
532eb171d5c2 2003-12-7 Brian Masney <masneyb@gftp.org>
masneyb
parents: 328
diff changeset
1303 }
532eb171d5c2 2003-12-7 Brian Masney <masneyb@gftp.org>
masneyb
parents: 328
diff changeset
1304
532eb171d5c2 2003-12-7 Brian Masney <masneyb@gftp.org>
masneyb
parents: 328
diff changeset
1305 if (error)
532eb171d5c2 2003-12-7 Brian Masney <masneyb@gftp.org>
masneyb
parents: 328
diff changeset
1306 {
532eb171d5c2 2003-12-7 Brian Masney <masneyb@gftp.org>
masneyb
parents: 328
diff changeset
1307 g_free (newstr);
532eb171d5c2 2003-12-7 Brian Masney <masneyb@gftp.org>
masneyb
parents: 328
diff changeset
1308 return (g_strdup (password));
532eb171d5c2 2003-12-7 Brian Masney <masneyb@gftp.org>
masneyb
parents: 328
diff changeset
1309 }
532eb171d5c2 2003-12-7 Brian Masney <masneyb@gftp.org>
masneyb
parents: 328
diff changeset
1310
532eb171d5c2 2003-12-7 Brian Masney <masneyb@gftp.org>
masneyb
parents: 328
diff changeset
1311 *newpos = '\0';
532eb171d5c2 2003-12-7 Brian Masney <masneyb@gftp.org>
masneyb
parents: 328
diff changeset
1312 return (newstr);
532eb171d5c2 2003-12-7 Brian Masney <masneyb@gftp.org>
masneyb
parents: 328
diff changeset
1313 }
532eb171d5c2 2003-12-7 Brian Masney <masneyb@gftp.org>
masneyb
parents: 328
diff changeset
1314
378
712d3810f4e1 2003-1-27 Brian Masney <masneyb@gftp.org>
masneyb
parents: 374
diff changeset
1315
712d3810f4e1 2003-1-27 Brian Masney <masneyb@gftp.org>
masneyb
parents: 374
diff changeset
1316 int
712d3810f4e1 2003-1-27 Brian Masney <masneyb@gftp.org>
masneyb
parents: 374
diff changeset
1317 gftp_get_transfer_action (gftp_request * request, gftp_file * fle)
712d3810f4e1 2003-1-27 Brian Masney <masneyb@gftp.org>
masneyb
parents: 374
diff changeset
1318 {
712d3810f4e1 2003-1-27 Brian Masney <masneyb@gftp.org>
masneyb
parents: 374
diff changeset
1319 intptr_t overwrite_default;
712d3810f4e1 2003-1-27 Brian Masney <masneyb@gftp.org>
masneyb
parents: 374
diff changeset
1320
712d3810f4e1 2003-1-27 Brian Masney <masneyb@gftp.org>
masneyb
parents: 374
diff changeset
1321 gftp_lookup_request_option (request, "overwrite_default", &overwrite_default);
712d3810f4e1 2003-1-27 Brian Masney <masneyb@gftp.org>
masneyb
parents: 374
diff changeset
1322
682
9b68dc473807 2005-2-4 Brian Masney <masneyb@gftp.org>
masneyb
parents: 653
diff changeset
1323 /* FIXME - add code to compare the file times and make a decision based
9b68dc473807 2005-2-4 Brian Masney <masneyb@gftp.org>
masneyb
parents: 653
diff changeset
1324 on that. Also if overwrite_default is enabled and the file sizes/dates are
9b68dc473807 2005-2-4 Brian Masney <masneyb@gftp.org>
masneyb
parents: 653
diff changeset
1325 the same, then skip the file */
9b68dc473807 2005-2-4 Brian Masney <masneyb@gftp.org>
masneyb
parents: 653
diff changeset
1326
378
712d3810f4e1 2003-1-27 Brian Masney <masneyb@gftp.org>
masneyb
parents: 374
diff changeset
1327 if (overwrite_default)
712d3810f4e1 2003-1-27 Brian Masney <masneyb@gftp.org>
masneyb
parents: 374
diff changeset
1328 fle->transfer_action = GFTP_TRANS_ACTION_OVERWRITE;
712d3810f4e1 2003-1-27 Brian Masney <masneyb@gftp.org>
masneyb
parents: 374
diff changeset
1329 else if (fle->startsize == fle->size)
712d3810f4e1 2003-1-27 Brian Masney <masneyb@gftp.org>
masneyb
parents: 374
diff changeset
1330 fle->transfer_action = GFTP_TRANS_ACTION_SKIP;
712d3810f4e1 2003-1-27 Brian Masney <masneyb@gftp.org>
masneyb
parents: 374
diff changeset
1331 else if (fle->startsize > fle->size)
712d3810f4e1 2003-1-27 Brian Masney <masneyb@gftp.org>
masneyb
parents: 374
diff changeset
1332 fle->transfer_action = GFTP_TRANS_ACTION_OVERWRITE;
712d3810f4e1 2003-1-27 Brian Masney <masneyb@gftp.org>
masneyb
parents: 374
diff changeset
1333 else
712d3810f4e1 2003-1-27 Brian Masney <masneyb@gftp.org>
masneyb
parents: 374
diff changeset
1334 fle->transfer_action = GFTP_TRANS_ACTION_RESUME;
712d3810f4e1 2003-1-27 Brian Masney <masneyb@gftp.org>
masneyb
parents: 374
diff changeset
1335
712d3810f4e1 2003-1-27 Brian Masney <masneyb@gftp.org>
masneyb
parents: 374
diff changeset
1336 return (fle->transfer_action);
712d3810f4e1 2003-1-27 Brian Masney <masneyb@gftp.org>
masneyb
parents: 374
diff changeset
1337 }
712d3810f4e1 2003-1-27 Brian Masney <masneyb@gftp.org>
masneyb
parents: 374
diff changeset
1338
483
4376ffeab64e 2004-6-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 460
diff changeset
1339
4376ffeab64e 2004-6-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 460
diff changeset
1340 char *
4376ffeab64e 2004-6-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 460
diff changeset
1341 gftp_get_share_dir (void)
4376ffeab64e 2004-6-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 460
diff changeset
1342 {
4376ffeab64e 2004-6-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 460
diff changeset
1343 static char *gftp_share_dir = NULL;
4376ffeab64e 2004-6-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 460
diff changeset
1344 char *envval;
4376ffeab64e 2004-6-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 460
diff changeset
1345
4376ffeab64e 2004-6-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 460
diff changeset
1346 if (gftp_share_dir == NULL)
4376ffeab64e 2004-6-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 460
diff changeset
1347 {
4376ffeab64e 2004-6-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 460
diff changeset
1348 envval = getenv ("GFTP_SHARE_DIR");
4376ffeab64e 2004-6-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 460
diff changeset
1349
4376ffeab64e 2004-6-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 460
diff changeset
1350 if (envval != NULL && *envval != '\0')
4376ffeab64e 2004-6-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 460
diff changeset
1351 gftp_share_dir = g_strdup (envval);
4376ffeab64e 2004-6-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 460
diff changeset
1352 else
4376ffeab64e 2004-6-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 460
diff changeset
1353 gftp_share_dir = SHARE_DIR;
4376ffeab64e 2004-6-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 460
diff changeset
1354 }
4376ffeab64e 2004-6-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 460
diff changeset
1355
4376ffeab64e 2004-6-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 460
diff changeset
1356 return (gftp_share_dir);
4376ffeab64e 2004-6-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 460
diff changeset
1357 }
4376ffeab64e 2004-6-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 460
diff changeset
1358