1
|
1 /*****************************************************************************/
|
|
2 /* config_file.c - config file routines */
|
122
|
3 /* Copyright (C) 1998-2003 Brian Masney <masneyb@gftp.org> */
|
1
|
4 /* */
|
|
5 /* This program is free software; you can redistribute it and/or modify */
|
|
6 /* it under the terms of the GNU General Public License as published by */
|
|
7 /* the Free Software Foundation; either version 2 of the License, or */
|
|
8 /* (at your option) any later version. */
|
|
9 /* */
|
|
10 /* This program is distributed in the hope that it will be useful, */
|
|
11 /* but WITHOUT ANY WARRANTY; without even the implied warranty of */
|
|
12 /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
|
|
13 /* GNU General Public License for more details. */
|
|
14 /* */
|
|
15 /* You should have received a copy of the GNU General Public License */
|
|
16 /* along with this program; if not, write to the Free Software */
|
|
17 /* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111 USA */
|
|
18 /*****************************************************************************/
|
|
19
|
|
20 #include "gftp.h"
|
33
|
21 static const char cvsid[] = "$Id$";
|
1
|
22
|
122
|
23 void
|
|
24 gftp_add_bookmark (gftp_bookmarks_var * newentry)
|
1
|
25 {
|
122
|
26 gftp_bookmarks_var * preventry, * folderentry, * endentry;
|
|
27 char *curpos;
|
1
|
28
|
122
|
29 if (!newentry->protocol)
|
124
|
30 newentry->protocol = g_strdup ("FTP");
|
1
|
31
|
122
|
32 /* We have to create the folders. For example, if we have
|
|
33 Debian Sites/Debian, we have to create a Debian Sites entry */
|
|
34 preventry = gftp_bookmarks;
|
|
35 if (preventry->children != NULL)
|
1
|
36 {
|
122
|
37 endentry = preventry->children;
|
|
38 while (endentry->next != NULL)
|
|
39 endentry = endentry->next;
|
|
40 }
|
|
41 else
|
|
42 endentry = NULL;
|
|
43 curpos = newentry->path;
|
|
44 while ((curpos = strchr (curpos, '/')) != NULL)
|
|
45 {
|
|
46 *curpos = '\0';
|
|
47 /* See if we already made this folder */
|
|
48 if ((folderentry = (gftp_bookmarks_var *)
|
|
49 g_hash_table_lookup (gftp_bookmarks_htable, newentry->path)) == NULL)
|
1
|
50 {
|
122
|
51 /* Allocate the individual folder. We have to do this for the edit
|
|
52 bookmarks feature */
|
|
53 folderentry = g_malloc0 (sizeof (*folderentry));
|
124
|
54 folderentry->path = g_strdup (newentry->path);
|
122
|
55 folderentry->prev = preventry;
|
|
56 folderentry->isfolder = 1;
|
|
57 g_hash_table_insert (gftp_bookmarks_htable, folderentry->path,
|
|
58 folderentry);
|
|
59 if (preventry->children == NULL)
|
|
60 preventry->children = folderentry;
|
1
|
61 else
|
122
|
62 endentry->next = folderentry;
|
|
63 preventry = folderentry;
|
|
64 endentry = NULL;
|
1
|
65 }
|
|
66 else
|
|
67 {
|
122
|
68 preventry = folderentry;
|
|
69 if (preventry->children != NULL)
|
|
70 {
|
|
71 endentry = preventry->children;
|
|
72 while (endentry->next != NULL)
|
|
73 endentry = endentry->next;
|
|
74 }
|
|
75 else
|
|
76 endentry = NULL;
|
1
|
77 }
|
122
|
78 *curpos = '/';
|
|
79 curpos++;
|
1
|
80 }
|
|
81
|
122
|
82 /* Get the parent node */
|
|
83 if ((curpos = strrchr (newentry->path, '/')) == NULL)
|
|
84 preventry = gftp_bookmarks;
|
|
85 else
|
1
|
86 {
|
122
|
87 *curpos = '\0';
|
|
88 preventry = (gftp_bookmarks_var *)
|
|
89 g_hash_table_lookup (gftp_bookmarks_htable, newentry->path);
|
|
90 *curpos = '/';
|
1
|
91 }
|
|
92
|
122
|
93 if (preventry->children != NULL)
|
1
|
94 {
|
122
|
95 endentry = preventry->children;
|
|
96 while (endentry->next != NULL)
|
|
97 endentry = endentry->next;
|
|
98 endentry->next = newentry;
|
1
|
99 }
|
122
|
100 else
|
|
101 preventry->children = newentry;
|
|
102 newentry->prev = preventry;
|
|
103 newentry->next = NULL;
|
|
104 g_hash_table_insert (gftp_bookmarks_htable, newentry->path, newentry);
|
1
|
105 }
|
|
106
|
|
107
|
122
|
108 static void
|
124
|
109 gftp_read_bookmarks (char *global_data_path)
|
1
|
110 {
|
|
111 char *tempstr, *temp1str, buf[255], *curpos;
|
199
|
112 gftp_config_vars * global_entry;
|
122
|
113 gftp_bookmarks_var * newentry;
|
1
|
114 FILE *bmfile;
|
|
115 size_t len;
|
|
116 int line;
|
|
117
|
|
118 if ((tempstr = expand_path (BOOKMARKS_FILE)) == NULL)
|
|
119 {
|
|
120 printf (_("gFTP Error: Bad bookmarks file name %s\n"), BOOKMARKS_FILE);
|
87
|
121 exit (1);
|
1
|
122 }
|
|
123
|
|
124 if (access (tempstr, F_OK) == -1)
|
|
125 {
|
124
|
126 temp1str = g_strdup_printf ("%s/bookmarks", global_data_path);
|
1
|
127 if (access (temp1str, F_OK) == -1)
|
|
128 {
|
|
129 printf (_("Warning: Cannot find master bookmark file %s\n"),
|
|
130 temp1str);
|
|
131 g_free (temp1str);
|
|
132 return;
|
|
133 }
|
|
134 copyfile (temp1str, tempstr);
|
|
135 g_free (temp1str);
|
|
136 }
|
58
|
137
|
1
|
138 if ((bmfile = fopen (tempstr, "r")) == NULL)
|
|
139 {
|
|
140 printf (_("gFTP Error: Cannot open bookmarks file %s: %s\n"), tempstr,
|
|
141 g_strerror (errno));
|
87
|
142 exit (1);
|
1
|
143 }
|
|
144 g_free (tempstr);
|
|
145
|
|
146 line = 0;
|
|
147 newentry = NULL;
|
|
148 while (fgets (buf, sizeof (buf), bmfile))
|
|
149 {
|
|
150 len = strlen (buf);
|
107
|
151 if (len > 0 && buf[len - 1] == '\n')
|
1
|
152 buf[--len] = '\0';
|
107
|
153 if (len > 0 && buf[len - 1] == '\r')
|
1
|
154 buf[--len] = '\0';
|
|
155 line++;
|
|
156
|
|
157 if (*buf == '[')
|
|
158 {
|
|
159 newentry = g_malloc0 (sizeof (*newentry));
|
|
160 for (; buf[len - 1] == ' ' || buf[len - 1] == ']'; buf[--len] = '\0');
|
124
|
161 newentry->path = g_strdup (buf + 1);
|
1
|
162 newentry->isfolder = 0;
|
122
|
163 gftp_add_bookmark (newentry);
|
1
|
164 }
|
|
165 else if (strncmp (buf, "hostname", 8) == 0 && newentry)
|
|
166 {
|
|
167 curpos = buf + 9;
|
|
168 if (newentry->hostname)
|
|
169 g_free (newentry->hostname);
|
124
|
170 newentry->hostname = g_strdup (curpos);
|
1
|
171 }
|
|
172 else if (strncmp (buf, "port", 4) == 0 && newentry)
|
|
173 newentry->port = strtol (buf + 5, NULL, 10);
|
|
174 else if (strncmp (buf, "protocol", 8) == 0 && newentry)
|
|
175 {
|
|
176 curpos = buf + 9;
|
|
177 if (newentry->protocol)
|
|
178 g_free (newentry->protocol);
|
124
|
179 newentry->protocol = g_strdup (curpos);
|
1
|
180 }
|
|
181 else if (strncmp (buf, "remote directory", 16) == 0 && newentry)
|
|
182 {
|
|
183 curpos = buf + 17;
|
|
184 if (newentry->remote_dir)
|
|
185 g_free (newentry->remote_dir);
|
124
|
186 newentry->remote_dir = g_strdup (curpos);
|
1
|
187 }
|
|
188 else if (strncmp (buf, "local directory", 15) == 0 && newentry)
|
|
189 {
|
|
190 curpos = buf + 16;
|
|
191 if (newentry->local_dir)
|
|
192 g_free (newentry->local_dir);
|
124
|
193 newentry->local_dir = g_strdup (curpos);
|
1
|
194 }
|
|
195 else if (strncmp (buf, "username", 8) == 0 && newentry)
|
|
196 {
|
|
197 curpos = buf + 9;
|
|
198 if (newentry->user)
|
|
199 g_free (newentry->user);
|
124
|
200 newentry->user = g_strdup (curpos);
|
1
|
201 }
|
|
202 else if (strncmp (buf, "password", 8) == 0 && newentry)
|
|
203 {
|
|
204 curpos = buf + 9;
|
|
205 if (newentry->pass)
|
|
206 g_free (newentry->pass);
|
124
|
207 newentry->pass = g_strdup (curpos);
|
1
|
208 newentry->save_password = *newentry->pass != '\0';
|
|
209 }
|
|
210 else if (strncmp (buf, "account", 7) == 0 && newentry)
|
|
211 {
|
|
212 curpos = buf + 8;
|
|
213 if (newentry->acct)
|
|
214 g_free (newentry->acct);
|
124
|
215 newentry->acct = g_strdup (curpos);
|
1
|
216 }
|
199
|
217 else if (*buf == '#' || *buf == '\0')
|
|
218 continue;
|
|
219 else
|
1
|
220 {
|
199
|
221 if ((curpos = strchr (buf, '=')) == NULL)
|
|
222 continue;
|
|
223 *curpos = '\0';
|
|
224
|
|
225 if ((global_entry = g_hash_table_lookup (gftp_global_options_htable,
|
|
226 buf)) == NULL ||
|
|
227 gftp_option_types[global_entry->otype].read_function == NULL)
|
|
228 {
|
|
229 printf (_("gFTP Warning: Skipping line %d in bookmarks file: %s\n"),
|
|
230 line, buf);
|
|
231 continue;
|
|
232 }
|
|
233
|
|
234 if (newentry->local_options_hash == NULL)
|
|
235 newentry->local_options_hash = g_hash_table_new (string_hash_function,
|
|
236 string_hash_compare);
|
|
237
|
|
238 newentry->num_local_options_vars++;
|
|
239 newentry->local_options_vars = g_realloc (newentry->local_options_vars,
|
|
240 sizeof (gftp_config_vars) * newentry->num_local_options_vars);
|
|
241
|
|
242 memcpy (&newentry->local_options_vars[newentry->num_local_options_vars - 1], global_entry,
|
|
243 sizeof (newentry->local_options_vars[newentry->num_local_options_vars - 1]));
|
|
244
|
|
245 newentry->local_options_vars[newentry->num_local_options_vars - 1].flags &= ~GFTP_CVARS_FLAGS_DYNMEM;
|
|
246 newentry->local_options_vars[newentry->num_local_options_vars - 1].value = NULL;
|
|
247
|
|
248 if (gftp_option_types[global_entry->otype].read_function (curpos + 1,
|
|
249 &newentry->local_options_vars[newentry->num_local_options_vars - 1], line) != 0)
|
|
250 {
|
|
251 printf (_("gFTP Warning: Skipping line %d in bookmarks file: %s\n"),
|
|
252 line, buf);
|
|
253 continue;
|
|
254 }
|
|
255
|
|
256 g_hash_table_insert (newentry->local_options_hash, newentry->local_options_vars[newentry->num_local_options_vars - 1].key, &newentry->local_options_vars[newentry->num_local_options_vars - 1]);
|
1
|
257 }
|
|
258 }
|
|
259 }
|
|
260
|
|
261
|
198
|
262 int
|
|
263 gftp_config_parse_args (char *str, int numargs, int lineno, char **first, ...)
|
1
|
264 {
|
|
265 char *curpos, *endpos, *pos, **dest, tempchar;
|
|
266 int ret, has_colon;
|
|
267 va_list argp;
|
|
268
|
|
269 ret = 1;
|
|
270 va_start (argp, first);
|
|
271 curpos = str;
|
|
272 dest = first;
|
|
273 *dest = NULL;
|
|
274 while (numargs > 0)
|
|
275 {
|
|
276 has_colon = 0;
|
|
277 if (numargs > 1)
|
|
278 {
|
|
279 if ((endpos = strchr (curpos, ':')) == NULL)
|
|
280 {
|
|
281 printf (_("gFTP Warning: Line %d doesn't have enough arguments\n"),
|
|
282 lineno);
|
|
283 ret = 0;
|
|
284 endpos = curpos + strlen (curpos);
|
|
285 }
|
|
286 else
|
|
287 {
|
|
288 /* Allow colons inside the fields. If you want a colon inside a
|
|
289 field, just put 2 colons in there */
|
|
290 while (endpos != NULL && *(endpos - 1) == '\\')
|
|
291 {
|
|
292 endpos = strchr (endpos + 1, ':');
|
|
293 has_colon = 1;
|
|
294 }
|
|
295 }
|
|
296 }
|
|
297 else
|
|
298 endpos = curpos + strlen (curpos);
|
|
299
|
|
300 *dest = g_malloc (endpos - curpos + 1);
|
|
301 tempchar = *endpos;
|
|
302 *endpos = '\0';
|
|
303 strcpy (*dest, curpos);
|
|
304 *endpos = tempchar;
|
|
305 if (has_colon)
|
|
306 {
|
|
307 pos = *dest;
|
|
308 curpos = *dest;
|
|
309 while (*pos != '\0')
|
|
310 {
|
|
311 if (*pos != '\\' && *(pos + 1) != ':')
|
|
312 *curpos++ = *pos++;
|
|
313 else
|
|
314 pos++;
|
|
315 }
|
|
316 *curpos = '\0';
|
|
317 }
|
|
318 if (*endpos == '\0')
|
|
319 break;
|
|
320 curpos = endpos + 1;
|
|
321 if (numargs > 1)
|
|
322 {
|
|
323 dest = va_arg (argp, char **);
|
|
324 *dest = NULL;
|
|
325 }
|
|
326 numargs--;
|
|
327 }
|
|
328
|
|
329 while (numargs > 1)
|
|
330 {
|
|
331 dest = va_arg (argp, char **);
|
|
332 *dest = g_malloc (1);
|
|
333 **dest = '\0';
|
|
334 numargs--;
|
|
335 }
|
|
336 va_end (argp);
|
|
337 return (1);
|
|
338 }
|
|
339
|
|
340
|
122
|
341 static void *
|
|
342 gftp_config_read_str (char *buf, int line)
|
|
343 {
|
|
344 char *ret;
|
|
345
|
|
346 ret = g_strdup (buf);
|
|
347 return (ret);
|
|
348 }
|
|
349
|
|
350
|
|
351 static void
|
|
352 gftp_config_write_str (FILE *fd, void *data)
|
|
353 {
|
|
354 fprintf (fd, "%s", (char *) data);
|
|
355 }
|
|
356
|
|
357
|
|
358 static void *
|
|
359 gftp_config_read_proxy (char *buf, int line)
|
|
360 {
|
|
361 gftp_proxy_hosts * host;
|
|
362 unsigned int nums[4];
|
|
363 char *pos;
|
|
364
|
|
365 host = g_malloc0 (sizeof (*host));
|
|
366 if ((pos = strchr (buf, '/')) == NULL)
|
|
367 host->domain = g_strdup (buf);
|
|
368 else
|
|
369 {
|
|
370 *pos = '\0';
|
|
371 sscanf (buf, "%u.%u.%u.%u", &nums[0], &nums[1], &nums[2], &nums[3]);
|
|
372 host->ipv4_network_address =
|
|
373 nums[0] << 24 | nums[1] << 16 | nums[2] << 8 | nums[3];
|
|
374
|
|
375 if (strchr (pos + 1, '.') == NULL)
|
|
376 host->ipv4_netmask = 0xffffffff << (32 - strtol (pos + 1, NULL, 10));
|
|
377 else
|
|
378 {
|
|
379 sscanf (pos + 1, "%u.%u.%u.%u", &nums[0], &nums[1], &nums[2],
|
|
380 &nums[3]);
|
|
381 host->ipv4_netmask =
|
|
382 nums[0] << 24 | nums[1] << 16 | nums[2] << 8 | nums[3];
|
|
383 }
|
|
384 }
|
|
385
|
|
386 return (host);
|
|
387 }
|
|
388
|
|
389
|
|
390 static void
|
|
391 gftp_config_write_proxy (FILE *fd, void *data)
|
|
392 {
|
|
393 gftp_proxy_hosts * host;
|
|
394
|
|
395 host = data;
|
|
396
|
|
397 if (host->domain)
|
|
398 fprintf (fd, "%s", host->domain);
|
|
399 else
|
|
400 fprintf (fd, "%d.%d.%d.%d/%d.%d.%d.%d",
|
|
401 host->ipv4_network_address >> 24 & 0xff,
|
|
402 host->ipv4_network_address >> 16 & 0xff,
|
|
403 host->ipv4_network_address >> 8 & 0xff,
|
|
404 host->ipv4_network_address & 0xff,
|
|
405 host->ipv4_netmask >> 24 & 0xff,
|
|
406 host->ipv4_netmask >> 16 & 0xff,
|
|
407 host->ipv4_netmask >> 8 & 0xff,
|
|
408 host->ipv4_netmask & 0xff);
|
|
409 }
|
|
410
|
|
411
|
|
412 static void *
|
|
413 gftp_config_read_ext (char *buf, int line)
|
|
414 {
|
|
415 gftp_file_extensions * tempext;
|
|
416
|
|
417 tempext = g_malloc (sizeof (*tempext));
|
198
|
418 gftp_config_parse_args (buf, 4, line, &tempext->ext, &tempext->filename,
|
|
419 &tempext->ascii_binary, &tempext->view_program);
|
122
|
420
|
|
421 tempext->stlen = strlen (tempext->ext);
|
|
422
|
|
423 return (tempext);
|
|
424 }
|
|
425
|
|
426
|
|
427 static void
|
|
428 gftp_config_write_ext (FILE *fd, void *data)
|
|
429 {
|
|
430 gftp_file_extensions * tempext;
|
|
431
|
|
432 tempext = data;
|
|
433 fprintf (fd, "%s:%s:%c:%s", tempext->ext, tempext->filename,
|
|
434 *tempext->ascii_binary == '\0' ? ' ' : *tempext->ascii_binary,
|
|
435 tempext->view_program);
|
|
436 }
|
|
437
|
|
438
|
|
439 gftp_config_list_vars gftp_config_list[] = {
|
|
440 {"dont_use_proxy", gftp_config_read_proxy, gftp_config_write_proxy,
|
|
441 NULL, 0,
|
|
442 N_("This section specifies which hosts are on the local subnet and won't need to go out the proxy server (if available). Syntax: dont_use_proxy=.domain or dont_use_proxy=network number/netmask")},
|
|
443 {"ext", gftp_config_read_ext, gftp_config_write_ext,
|
|
444 NULL, 0,
|
|
445 N_("ext=file extenstion:XPM file:Ascii or Binary (A or B):viewer program. Note: All arguments except the file extension are optional")},
|
|
446 {"localhistory", gftp_config_read_str, gftp_config_write_str,
|
|
447 NULL, 0, NULL},
|
|
448 {"remotehistory", gftp_config_read_str, gftp_config_write_str,
|
|
449 NULL, 0, NULL},
|
|
450 {"hosthistory", gftp_config_read_str, gftp_config_write_str,
|
|
451 NULL, 0, NULL},
|
|
452 {"porthistory", gftp_config_read_str, gftp_config_write_str,
|
|
453 NULL, 0, NULL},
|
|
454 {"userhistory", gftp_config_read_str, gftp_config_write_str,
|
|
455 NULL, 0, NULL},
|
|
456 {NULL, NULL, NULL,
|
|
457 NULL, 0, NULL}
|
|
458 };
|
|
459
|
|
460
|
|
461 static void
|
|
462 gftp_setup_global_options (gftp_config_vars * cvars)
|
|
463 {
|
|
464 int i;
|
|
465
|
|
466 for (i=0; cvars[i].key != NULL; i++)
|
|
467 {
|
136
|
468 if (cvars[i].key != NULL && *cvars[i].key != '\0')
|
122
|
469 g_hash_table_insert (gftp_global_options_htable,
|
|
470 cvars[i].key, &cvars[i]);
|
|
471 }
|
|
472 }
|
|
473
|
|
474
|
|
475 void
|
124
|
476 gftp_read_config_file (char *global_data_path)
|
122
|
477 {
|
|
478 char *tempstr, *temp1str, *curpos, buf[255];
|
|
479 gftp_config_list_vars * tmplistvar;
|
|
480 gftp_config_vars * tmpconfigvar;
|
125
|
481 char **protocol_list;
|
122
|
482 FILE *conffile;
|
|
483 int line, i;
|
|
484 size_t len;
|
|
485
|
|
486 gftp_global_options_htable = g_hash_table_new (string_hash_function,
|
|
487 string_hash_compare);
|
|
488
|
|
489 gftp_register_config_vars (gftp_global_config_vars);
|
|
490
|
125
|
491 protocol_list = NULL;
|
122
|
492 for (i=0; gftp_protocols[i].register_options != NULL; i++)
|
|
493 {
|
125
|
494 if (gftp_protocols[i].shown)
|
|
495 {
|
|
496 protocol_list = g_realloc (protocol_list, sizeof (char *) * (i + 2));
|
|
497 protocol_list[i] = gftp_protocols[i].name;
|
|
498 protocol_list[i + 1] = NULL;
|
|
499 }
|
|
500
|
122
|
501 if (gftp_protocols[i].register_options != NULL)
|
|
502 gftp_protocols[i].register_options ();
|
|
503 }
|
|
504
|
125
|
505 if ((tmpconfigvar = g_hash_table_lookup (gftp_global_options_htable,
|
|
506 "default_protocol")) != NULL)
|
201
|
507 {
|
|
508 tmpconfigvar->listdata = protocol_list;
|
|
509 tmpconfigvar->flags |= GFTP_CVARS_FLAGS_DYNLISTMEM;
|
|
510 }
|
125
|
511
|
122
|
512 gftp_config_list_htable = g_hash_table_new (string_hash_function,
|
|
513 string_hash_compare);
|
|
514
|
|
515 for (i=0; gftp_config_list[i].key != NULL; i++)
|
|
516 {
|
|
517 g_hash_table_insert (gftp_config_list_htable, gftp_config_list[i].key,
|
|
518 &gftp_config_list[i]);
|
|
519 }
|
|
520
|
|
521 if ((tempstr = expand_path (CONFIG_FILE)) == NULL)
|
|
522 {
|
|
523 printf (_("gFTP Error: Bad config file name %s\n"), CONFIG_FILE);
|
|
524 exit (1);
|
|
525 }
|
|
526
|
|
527 if (access (tempstr, F_OK) == -1)
|
|
528 {
|
|
529 temp1str = expand_path (BASE_CONF_DIR);
|
|
530 if (access (temp1str, F_OK) == -1)
|
|
531 {
|
|
532 if (mkdir (temp1str, S_IRUSR | S_IWUSR | S_IXUSR) != 0)
|
|
533 {
|
|
534 printf (_("gFTP Error: Could not make directory %s: %s\n"),
|
|
535 temp1str, g_strerror (errno));
|
|
536 exit (1);
|
|
537 }
|
|
538 }
|
|
539 g_free (temp1str);
|
|
540
|
124
|
541 temp1str = g_strdup_printf ("%s/gftprc", global_data_path);
|
122
|
542 if (access (temp1str, F_OK) == -1)
|
|
543 {
|
|
544 printf (_("gFTP Error: Cannot find master config file %s\n"),
|
|
545 temp1str);
|
|
546 printf (_("Did you do a make install?\n"));
|
|
547 exit (1);
|
|
548 }
|
|
549 copyfile (temp1str, tempstr);
|
|
550 g_free (temp1str);
|
|
551 }
|
|
552
|
|
553 if ((conffile = fopen (tempstr, "r")) == NULL)
|
|
554 {
|
|
555 printf (_("gFTP Error: Cannot open config file %s: %s\n"), CONFIG_FILE,
|
|
556 g_strerror (errno));
|
|
557 exit (1);
|
|
558 }
|
|
559 g_free (tempstr);
|
|
560
|
|
561 line = 0;
|
|
562 while (fgets (buf, sizeof (buf), conffile))
|
|
563 {
|
|
564 len = strlen (buf);
|
|
565 if (len > 0 && buf[len - 1] == '\n')
|
|
566 buf[--len] = '\0';
|
|
567 if (len > 0 && buf[len - 1] == '\r')
|
|
568 buf[--len] = '\0';
|
|
569 line++;
|
|
570
|
|
571 if (*buf == '#' || *buf == '\0')
|
|
572 continue;
|
|
573
|
|
574 if ((curpos = strchr (buf, '=')) == NULL)
|
|
575 continue;
|
|
576
|
|
577 *curpos = '\0';
|
|
578
|
|
579 if ((tmplistvar = g_hash_table_lookup (gftp_config_list_htable,
|
|
580 buf)) != NULL)
|
|
581 {
|
|
582 tmplistvar->list = g_list_append (tmplistvar->list,
|
|
583 tmplistvar->read_func (curpos + 1,
|
|
584 line));
|
|
585 tmplistvar->num_items++;
|
|
586 }
|
|
587 else if ((tmpconfigvar = g_hash_table_lookup (gftp_global_options_htable,
|
|
588 buf)) != NULL &&
|
|
589 gftp_option_types[tmpconfigvar->otype].read_function != NULL)
|
|
590 {
|
|
591 if (gftp_option_types[tmpconfigvar->otype].read_function (curpos + 1,
|
|
592 tmpconfigvar, line) != 0)
|
|
593 {
|
|
594 printf (_("Terminating due to parse errors at line %d in the config file\n"), line);
|
|
595 exit (1);
|
|
596 }
|
|
597 }
|
|
598 else
|
|
599 {
|
|
600 printf (_("gFTP Warning: Skipping line %d in config file: %s\n"),
|
|
601 line, buf);
|
|
602 }
|
|
603 }
|
|
604
|
|
605 if ((tempstr = expand_path (LOG_FILE)) == NULL)
|
|
606 {
|
|
607 printf (_("gFTP Error: Bad log file name %s\n"), LOG_FILE);
|
|
608 exit (1);
|
|
609 }
|
|
610
|
|
611 if ((gftp_logfd = fopen (tempstr, "w")) == NULL)
|
|
612 {
|
|
613 printf (_("gFTP Warning: Cannot open %s for writing: %s\n"),
|
|
614 tempstr, g_strerror (errno));
|
|
615 }
|
|
616 g_free (tempstr);
|
|
617
|
|
618 gftp_bookmarks = g_malloc0 (sizeof (*gftp_bookmarks));
|
|
619 gftp_bookmarks->isfolder = 1;
|
|
620 gftp_bookmarks->path = g_malloc0 (1);
|
|
621 gftp_bookmarks_htable = g_hash_table_new (string_hash_function, string_hash_compare);
|
|
622
|
124
|
623 gftp_read_bookmarks (global_data_path);
|
122
|
624 }
|
|
625
|
|
626
|
|
627 static void
|
|
628 write_comment (FILE * fd, const char *comment)
|
|
629 {
|
|
630 const char *pos, *endpos;
|
|
631
|
|
632 fwrite ("# ", 1, 2, fd);
|
|
633 pos = comment;
|
|
634 while (strlen (pos) > 76)
|
|
635 {
|
|
636 for (endpos = pos + 76; *endpos != ' ' && endpos > pos; endpos--);
|
|
637 if (endpos == pos)
|
|
638 {
|
|
639 for (endpos = pos + 76; *endpos != ' ' && *endpos != '\0';
|
|
640 endpos++);
|
|
641 }
|
|
642 fwrite (pos, 1, endpos - pos, fd);
|
|
643 fwrite ("\n# ", 1, 3, fd);
|
|
644 if (*endpos == '\0')
|
|
645 {
|
|
646 pos = endpos;
|
|
647 break;
|
|
648 }
|
|
649 else
|
|
650 pos = endpos + 1;
|
|
651 }
|
|
652 if (strlen (pos) > 1)
|
|
653 {
|
|
654 fwrite (pos, 1, strlen (pos), fd);
|
|
655 fwrite ("\n", 1, 1, fd);
|
|
656 }
|
|
657 }
|
|
658
|
|
659
|
|
660 void
|
|
661 gftp_write_bookmarks_file (void)
|
|
662 {
|
|
663 gftp_bookmarks_var * tempentry;
|
|
664 char *bmhdr, *tempstr;
|
|
665 FILE * bmfile;
|
199
|
666 int i;
|
122
|
667
|
|
668 bmhdr = N_("Bookmarks file for gFTP. Copyright (C) 1998-2003 Brian Masney <masneyb@gftp.org>. Warning: Any comments that you add to this file WILL be overwritten");
|
|
669
|
|
670 if ((tempstr = expand_path (BOOKMARKS_FILE)) == NULL)
|
|
671 {
|
|
672 printf (_("gFTP Error: Bad bookmarks file name %s\n"), CONFIG_FILE);
|
|
673 exit (1);
|
|
674 }
|
|
675
|
|
676 if ((bmfile = fopen (tempstr, "w+")) == NULL)
|
|
677 {
|
|
678 printf (_("gFTP Error: Cannot open bookmarks file %s: %s\n"),
|
|
679 CONFIG_FILE, g_strerror (errno));
|
|
680 exit (1);
|
|
681 }
|
|
682
|
|
683 g_free (tempstr);
|
|
684
|
|
685 write_comment (bmfile, _(bmhdr));
|
|
686 fwrite ("\n", 1, 1, bmfile);
|
|
687
|
|
688 tempentry = gftp_bookmarks->children;
|
|
689 while (tempentry != NULL)
|
|
690 {
|
|
691 if (tempentry->children != NULL)
|
|
692 {
|
|
693 tempentry = tempentry->children;
|
|
694 continue;
|
|
695 }
|
|
696 tempstr = tempentry->path;
|
|
697 while (*tempstr == '/')
|
|
698 tempstr++;
|
|
699 fprintf (bmfile,
|
|
700 "[%s]\nhostname=%s\nport=%d\nprotocol=%s\nremote directory=%s\nlocal directory=%s\nusername=%s\npassword=%s\naccount=%s\n",
|
|
701 tempstr, tempentry->hostname == NULL ? "" : tempentry->hostname,
|
|
702 tempentry->port, tempentry->protocol == NULL
|
|
703 || *tempentry->protocol ==
|
|
704 '\0' ? gftp_protocols[0].name : tempentry->protocol,
|
|
705 tempentry->remote_dir == NULL ? "" : tempentry->remote_dir,
|
|
706 tempentry->local_dir == NULL ? "" : tempentry->local_dir,
|
|
707 tempentry->user == NULL ? "" : tempentry->user,
|
|
708 !tempentry->save_password
|
|
709 || tempentry->pass == NULL ? "" : tempentry->pass,
|
|
710 tempentry->acct == NULL ? "" : tempentry->acct);
|
|
711
|
199
|
712 if (tempentry->local_options_vars != NULL)
|
|
713 {
|
|
714 for (i=0; i<tempentry->num_local_options_vars; i++)
|
|
715 {
|
|
716 fprintf (bmfile, "%s=", tempentry->local_options_vars[i].key);
|
|
717 gftp_option_types[tempentry->local_options_vars[i].otype].write_function (&tempentry->local_options_vars[i], bmfile, 1);
|
|
718 fprintf (bmfile, "\n");
|
|
719 }
|
|
720 }
|
122
|
721
|
|
722 fprintf (bmfile, "\n");
|
|
723
|
|
724 if (tempentry->next == NULL)
|
|
725 {
|
|
726 tempentry = tempentry->prev;
|
|
727 while (tempentry->next == NULL && tempentry->prev != NULL)
|
|
728 tempentry = tempentry->prev;
|
|
729 tempentry = tempentry->next;
|
|
730 }
|
|
731 else
|
|
732 tempentry = tempentry->next;
|
|
733 }
|
|
734
|
|
735 fclose (bmfile);
|
|
736 }
|
|
737
|
|
738
|
|
739 void
|
|
740 gftp_write_config_file (void)
|
|
741 {
|
|
742 gftp_config_vars * cv;
|
|
743 GList *templist;
|
|
744 FILE *conffile;
|
|
745 char *tempstr;
|
|
746 int i;
|
|
747
|
|
748 if ((tempstr = expand_path (CONFIG_FILE)) == NULL)
|
|
749 {
|
|
750 printf (_("gFTP Error: Bad config file name %s\n"), CONFIG_FILE);
|
|
751 exit (1);
|
|
752 }
|
|
753
|
|
754 if ((conffile = fopen (tempstr, "w+")) == NULL)
|
|
755 {
|
|
756 printf (_("gFTP Error: Cannot open config file %s: %s\n"), CONFIG_FILE,
|
|
757 g_strerror (errno));
|
|
758 exit (1);
|
|
759 }
|
|
760
|
|
761 g_free (tempstr);
|
|
762
|
|
763 write_comment (conffile, _("Config file for gFTP. Copyright (C) 1998-2003 Brian Masney <masneyb@gftp.org>. Warning: Any comments that you add to this file WILL be overwritten. If a entry has a (*) in it's comment, you can't change it inside gFTP"));
|
|
764
|
|
765 for (templist = gftp_options_list;
|
|
766 templist != NULL;
|
|
767 templist = templist->next)
|
|
768 {
|
|
769 cv = templist->data;
|
|
770
|
|
771 for (i=0; cv[i].key != NULL; i++)
|
|
772 {
|
|
773 if (gftp_option_types[cv[i].otype].write_function == NULL ||
|
|
774 *cv[i].key == '\0')
|
|
775 continue;
|
|
776
|
|
777 fprintf (conffile, "\n");
|
|
778 if (cv[i].comment != NULL)
|
|
779 write_comment (conffile, _(cv[i].comment));
|
|
780
|
|
781 fprintf (conffile, "%s=", cv[i].key);
|
|
782 gftp_option_types[cv[i].otype].write_function (&cv[i], conffile, 1);
|
|
783 fprintf (conffile, "\n");
|
|
784 }
|
|
785 }
|
|
786
|
218
|
787 for (i=0; gftp_config_list[i].key != NULL; i++)
|
122
|
788 {
|
218
|
789 if (gftp_config_list[i].header == NULL &&
|
|
790 gftp_config_list[i].list == NULL)
|
|
791 continue;
|
|
792
|
122
|
793 fprintf (conffile, "\n");
|
|
794 if (gftp_config_list[i].header != NULL)
|
|
795 write_comment (conffile, _(gftp_config_list[i].header));
|
|
796
|
218
|
797 for (templist = gftp_config_list[i].list;
|
122
|
798 templist != NULL;
|
|
799 templist = templist->next)
|
|
800 {
|
|
801 fprintf (conffile, "%s=", gftp_config_list[i].key);
|
|
802 gftp_config_list[i].write_func (conffile, templist->data);
|
|
803 fprintf (conffile, "\n");
|
|
804 }
|
|
805 }
|
|
806
|
|
807 fclose (conffile);
|
|
808 }
|
|
809
|
|
810
|
1
|
811 GHashTable *
|
122
|
812 build_bookmarks_hash_table (gftp_bookmarks_var * entry)
|
1
|
813 {
|
122
|
814 gftp_bookmarks_var * tempentry;
|
1
|
815 GHashTable * htable;
|
|
816
|
|
817 htable = g_hash_table_new (string_hash_function, string_hash_compare);
|
|
818 tempentry = entry;
|
|
819 while (tempentry != NULL)
|
|
820 {
|
|
821 g_hash_table_insert (htable, tempentry->path, tempentry);
|
|
822 if (tempentry->children != NULL)
|
|
823 {
|
|
824 tempentry = tempentry->children;
|
|
825 continue;
|
|
826 }
|
|
827 while (tempentry->next == NULL && tempentry->prev != NULL)
|
|
828 tempentry = tempentry->prev;
|
|
829 tempentry = tempentry->next;
|
|
830 }
|
|
831 return (htable);
|
|
832 }
|
|
833
|
|
834
|
|
835 void
|
122
|
836 print_bookmarks (gftp_bookmarks_var * bookmarks)
|
1
|
837 {
|
122
|
838 gftp_bookmarks_var * tempentry;
|
1
|
839
|
|
840 tempentry = bookmarks->children;
|
|
841 while (tempentry != NULL)
|
|
842 {
|
|
843 printf ("Path: %s (%d)\n", tempentry->path, tempentry->children != NULL);
|
|
844 if (tempentry->children != NULL)
|
|
845 {
|
|
846 tempentry = tempentry->children;
|
|
847 continue;
|
|
848 }
|
|
849
|
|
850 if (tempentry->next == NULL)
|
|
851 {
|
|
852 while (tempentry->next == NULL && tempentry->prev != NULL)
|
|
853 tempentry = tempentry->prev;
|
|
854 tempentry = tempentry->next;
|
|
855 }
|
|
856 else
|
|
857 tempentry = tempentry->next;
|
|
858 }
|
|
859 }
|
|
860
|
122
|
861
|
|
862 static int
|
|
863 gftp_config_file_read_text (char *str, gftp_config_vars * cv, int line)
|
|
864 {
|
136
|
865 if (cv->flags & GFTP_CVARS_FLAGS_DYNMEM && cv->value != NULL)
|
|
866 g_free (cv->value);
|
|
867
|
122
|
868 if (str != NULL)
|
|
869 {
|
|
870 cv->value = g_strdup (str);
|
136
|
871 cv->flags |= GFTP_CVARS_FLAGS_DYNMEM;
|
122
|
872 return (0);
|
|
873 }
|
|
874 else
|
136
|
875 {
|
|
876 cv->value = NULL;
|
|
877 cv->flags &= ~GFTP_CVARS_FLAGS_DYNMEM;
|
|
878 return (-1);
|
|
879 }
|
122
|
880 }
|
|
881
|
|
882
|
|
883 static int
|
|
884 gftp_config_file_write_text (gftp_config_vars * cv, FILE * fd, int to_config_file)
|
|
885 {
|
|
886 char *outstr;
|
|
887
|
|
888 if (cv->value != NULL)
|
|
889 {
|
|
890 outstr = cv->value;
|
|
891 if (*outstr != '\0')
|
|
892 fprintf (fd, "%s", outstr);
|
|
893 return (0);
|
|
894 }
|
|
895 else
|
|
896 return (-1);
|
|
897 }
|
|
898
|
|
899
|
|
900 static int
|
|
901 gftp_config_file_write_hidetext (gftp_config_vars * cv, FILE * fd, int to_config_file)
|
|
902 {
|
|
903 char *outstr;
|
|
904
|
|
905 if (cv->value != NULL)
|
|
906 {
|
|
907 outstr = cv->value;
|
|
908 if (*outstr != '\0')
|
|
909 {
|
|
910 if (to_config_file)
|
|
911 fprintf (fd, "%s", outstr);
|
|
912 else
|
|
913 fprintf (fd, "*****");
|
|
914 }
|
|
915 return (0);
|
|
916 }
|
|
917 else
|
|
918 return (-1);
|
|
919 }
|
|
920
|
|
921
|
207
|
922 static void
|
|
923 gftp_config_file_copy_text (gftp_config_vars * cv, gftp_config_vars * dest_cv)
|
|
924 {
|
|
925 if (dest_cv->flags & GFTP_CVARS_FLAGS_DYNMEM && dest_cv->value != NULL)
|
|
926 g_free (dest_cv->value);
|
|
927
|
|
928 if (cv->value != NULL)
|
|
929 {
|
|
930 dest_cv->value = g_strdup ((char *) cv->value);
|
|
931 dest_cv->flags |= GFTP_CVARS_FLAGS_DYNMEM;
|
|
932 }
|
|
933 else
|
|
934 dest_cv->value = NULL;
|
|
935 }
|
|
936
|
|
937
|
227
|
938 static int
|
|
939 gftp_config_file_compare_text (gftp_config_vars * cv1, gftp_config_vars * cv2)
|
|
940 {
|
|
941 char *str1, *str2;
|
|
942
|
|
943 str1 = cv1->value;
|
|
944 str2 = cv2->value;
|
|
945
|
|
946 if (cv1->value == NULL && cv2->value == NULL)
|
|
947 return (0);
|
|
948
|
|
949 if ((cv1->value == NULL && cv2->value != NULL) ||
|
|
950 (cv1->value != NULL && cv2->value == NULL))
|
|
951 return (-1);
|
|
952
|
|
953 return (strcmp (str1, str2));
|
|
954 }
|
|
955
|
|
956
|
207
|
957 static void
|
|
958 gftp_config_file_copy_ptr_contents (gftp_config_vars * cv, gftp_config_vars * dest_cv)
|
|
959 {
|
|
960 memcpy (&dest_cv->value, &cv->value, sizeof (dest_cv->value));
|
|
961 }
|
|
962
|
122
|
963 static int
|
|
964 gftp_config_file_read_int (char *str, gftp_config_vars * cv, int line)
|
|
965 {
|
|
966 cv->value = GINT_TO_POINTER(strtol (str, NULL, 10));
|
|
967 return (0);
|
|
968 }
|
|
969
|
|
970
|
|
971 static int
|
|
972 gftp_config_file_write_int (gftp_config_vars * cv, FILE * fd, int to_config_file)
|
|
973 {
|
|
974 fprintf (fd, "%d", GPOINTER_TO_INT(cv->value));
|
|
975 return (0);
|
|
976 }
|
|
977
|
|
978
|
|
979 static int
|
227
|
980 gftp_config_file_compare_int (gftp_config_vars * cv1, gftp_config_vars * cv2)
|
|
981 {
|
|
982 return (GPOINTER_TO_INT(cv1->value) == GPOINTER_TO_INT(cv2->value) ? 0 : -1);
|
|
983 }
|
|
984
|
|
985
|
|
986 static int
|
122
|
987 gftp_config_file_read_checkbox (char *str, gftp_config_vars * cv, int line)
|
|
988 {
|
|
989 cv->value = GINT_TO_POINTER(strtol (str, NULL, 10) ? 1 : 0);
|
|
990 return (0);
|
|
991 }
|
|
992
|
|
993
|
|
994 static int
|
|
995 gftp_config_file_read_float (char *str, gftp_config_vars * cv, int line)
|
|
996 {
|
131
|
997 float f;
|
|
998
|
151
|
999 f = strtod (str, NULL);
|
131
|
1000 memcpy (&cv->value, &f, sizeof (cv->value));
|
122
|
1001 return (0);
|
|
1002 }
|
|
1003
|
|
1004
|
|
1005 static int
|
|
1006 gftp_config_file_write_float (gftp_config_vars * cv, FILE * fd, int to_config_file)
|
|
1007 {
|
131
|
1008 float f;
|
|
1009
|
|
1010 memcpy (&f, &cv->value, sizeof (f));
|
|
1011 fprintf (fd, "%.2f", f);
|
122
|
1012 return (0);
|
|
1013 }
|
|
1014
|
|
1015
|
|
1016 static int
|
227
|
1017 gftp_config_file_compare_float (gftp_config_vars * cv1, gftp_config_vars * cv2)
|
|
1018 {
|
|
1019 float f1, f2;
|
|
1020
|
|
1021 memcpy (&f1, &cv1->value, sizeof (f1));
|
|
1022 memcpy (&f2, &cv2->value, sizeof (f2));
|
|
1023 return (f1 == f2 ? 0 : -1);
|
|
1024 }
|
|
1025
|
|
1026
|
|
1027 static int
|
122
|
1028 gftp_config_file_read_color (char *str, gftp_config_vars * cv, int line)
|
|
1029 {
|
|
1030 char *red, *green, *blue;
|
|
1031 gftp_color * color;
|
|
1032
|
136
|
1033 if (cv->flags & GFTP_CVARS_FLAGS_DYNMEM && cv->value != NULL)
|
|
1034 g_free (cv->value);
|
|
1035
|
198
|
1036 gftp_config_parse_args (str, 3, line, &red, &green, &blue);
|
122
|
1037
|
|
1038 color = g_malloc (sizeof (*color));
|
|
1039 color->red = strtol (red, NULL, 16);
|
|
1040 color->green = strtol (green, NULL, 16);
|
|
1041 color->blue = strtol (blue, NULL, 16);
|
|
1042 g_free (red);
|
|
1043 g_free (green);
|
|
1044 g_free (blue);
|
|
1045
|
|
1046 cv->value = color;
|
136
|
1047 cv->flags |= GFTP_CVARS_FLAGS_DYNMEM;
|
122
|
1048
|
|
1049 return (0);
|
|
1050 }
|
|
1051
|
|
1052
|
|
1053 static int
|
|
1054 gftp_config_file_write_color (gftp_config_vars * cv, FILE * fd, int to_config_file)
|
|
1055 {
|
|
1056 gftp_color * color;
|
|
1057
|
|
1058 color = cv->value;
|
|
1059 fprintf (fd, "%x:%x:%x", color->red, color->green, color->blue);
|
|
1060 return (0);
|
|
1061 }
|
|
1062
|
|
1063
|
207
|
1064 static void
|
|
1065 gftp_config_file_copy_color (gftp_config_vars * cv, gftp_config_vars * dest_cv)
|
|
1066 {
|
|
1067 if (dest_cv->flags & GFTP_CVARS_FLAGS_DYNMEM && dest_cv->value != NULL)
|
|
1068 g_free (dest_cv->value);
|
|
1069
|
|
1070 dest_cv->value = g_malloc (sizeof (gftp_color));
|
|
1071 memcpy (dest_cv->value, cv->value, sizeof (gftp_color));
|
|
1072 dest_cv->flags |= GFTP_CVARS_FLAGS_DYNMEM;
|
|
1073 }
|
|
1074
|
|
1075
|
122
|
1076 static int
|
227
|
1077 gftp_config_file_compare_color (gftp_config_vars * cv1, gftp_config_vars * cv2)
|
|
1078 {
|
|
1079 gftp_color * color1, * color2;
|
|
1080
|
|
1081 color1 = cv1->value;
|
|
1082 color2 = cv2->value;
|
|
1083
|
|
1084 return (color1->red == color2->red && color1->green == color2->green &&
|
|
1085 color1->blue == color2->blue ? 0 : -1);
|
|
1086 }
|
|
1087
|
|
1088
|
|
1089 static int
|
122
|
1090 gftp_config_file_read_intcombo (char *str, gftp_config_vars * cv, int line)
|
|
1091 {
|
|
1092 char **clist;
|
|
1093 int i;
|
|
1094
|
|
1095 cv->value = 0;
|
|
1096 if (cv->listdata != NULL)
|
|
1097 {
|
|
1098 clist = cv->listdata;
|
|
1099 for (i=0; clist[i] != NULL; i++)
|
|
1100 {
|
125
|
1101 if (strcasecmp (clist[i], str) == 0)
|
122
|
1102 {
|
|
1103 cv->value = GINT_TO_POINTER(i);
|
|
1104 break;
|
|
1105 }
|
|
1106 }
|
|
1107 }
|
|
1108
|
|
1109 return (0);
|
|
1110 }
|
|
1111
|
|
1112
|
|
1113 static int
|
|
1114 gftp_config_file_write_intcombo (gftp_config_vars * cv, FILE * fd, int to_config_file)
|
|
1115 {
|
|
1116 char **clist;
|
|
1117
|
|
1118 clist = cv->listdata;
|
|
1119 if (clist != NULL)
|
125
|
1120 fprintf (fd, "%s", clist[GPOINTER_TO_INT(cv->value)]);
|
122
|
1121 else
|
|
1122 fprintf (fd, _("<unknown>"));
|
|
1123
|
|
1124 return (0);
|
|
1125 }
|
|
1126
|
|
1127
|
125
|
1128 static int
|
|
1129 gftp_config_file_read_textcombo (char *str, gftp_config_vars * cv, int line)
|
|
1130 {
|
|
1131 char **clist;
|
|
1132 int i;
|
|
1133
|
|
1134 cv->value = NULL;
|
|
1135 if (cv->listdata != NULL)
|
|
1136 {
|
|
1137 clist = cv->listdata;
|
|
1138 for (i=0; clist[i] != NULL; i++)
|
|
1139 {
|
|
1140 if (strcasecmp (clist[i], str) == 0)
|
|
1141 {
|
|
1142 cv->value = clist[i];
|
|
1143 break;
|
|
1144 }
|
|
1145 }
|
|
1146 }
|
|
1147
|
|
1148 return (0);
|
|
1149 }
|
|
1150
|
|
1151
|
|
1152 /* Note, the index numbers of this array must match up to the numbers in
|
122
|
1153 gftp_option_type_enum in gftp.h */
|
|
1154 gftp_option_type_var gftp_option_types[] = {
|
227
|
1155 {gftp_config_file_read_text, gftp_config_file_write_text,
|
|
1156 gftp_config_file_copy_text, gftp_config_file_compare_text, NULL, NULL, NULL},
|
|
1157 {gftp_config_file_read_textcombo, gftp_config_file_write_text,
|
|
1158 gftp_config_file_copy_text, gftp_config_file_compare_text, NULL, NULL, NULL},
|
|
1159 {gftp_config_file_read_text, gftp_config_file_write_text,
|
|
1160 gftp_config_file_copy_text, gftp_config_file_compare_text, NULL, NULL, NULL},
|
|
1161 {gftp_config_file_read_text, gftp_config_file_write_hidetext,
|
|
1162 gftp_config_file_copy_text, gftp_config_file_compare_text, NULL, NULL, NULL},
|
|
1163 {gftp_config_file_read_int, gftp_config_file_write_int,
|
|
1164 gftp_config_file_copy_ptr_contents, gftp_config_file_compare_int,
|
|
1165 NULL, NULL, NULL},
|
|
1166 {gftp_config_file_read_checkbox, gftp_config_file_write_int,
|
|
1167 gftp_config_file_copy_ptr_contents, gftp_config_file_compare_int,
|
|
1168 NULL, NULL, NULL},
|
|
1169 {gftp_config_file_read_intcombo, gftp_config_file_write_intcombo,
|
|
1170 gftp_config_file_copy_ptr_contents, gftp_config_file_compare_int,
|
|
1171 NULL, NULL, NULL},
|
|
1172 {gftp_config_file_read_float, gftp_config_file_write_float,
|
|
1173 gftp_config_file_copy_ptr_contents, gftp_config_file_compare_float,
|
|
1174 NULL, NULL, NULL},
|
|
1175 {gftp_config_file_read_color, gftp_config_file_write_color,
|
|
1176 gftp_config_file_copy_color, gftp_config_file_compare_color,
|
|
1177 NULL, NULL, NULL},
|
|
1178 {NULL, NULL, NULL, NULL, NULL, NULL},
|
|
1179 {NULL, NULL, NULL, NULL, NULL, NULL}
|
122
|
1180 };
|
|
1181
|
|
1182
|
|
1183 void
|
|
1184 gftp_lookup_global_option (char * key, void *value)
|
|
1185 {
|
|
1186 gftp_config_list_vars * tmplistvar;
|
|
1187 gftp_config_vars * tmpconfigvar;
|
|
1188
|
|
1189 if (gftp_global_options_htable != NULL &&
|
|
1190 (tmpconfigvar = g_hash_table_lookup (gftp_global_options_htable,
|
|
1191 key)) != NULL)
|
124
|
1192 memcpy (value, &tmpconfigvar->value, sizeof (value));
|
122
|
1193 else if ((tmplistvar = g_hash_table_lookup (gftp_config_list_htable,
|
|
1194 key)) != NULL)
|
124
|
1195 *(gftp_config_list_vars **) value = tmplistvar;
|
122
|
1196 else
|
|
1197 {
|
|
1198 fprintf (stderr, _("FATAL gFTP Error: Config option '%s' not found in global hash table\n"), key);
|
|
1199 exit (1);
|
|
1200 }
|
|
1201 }
|
|
1202
|
|
1203
|
|
1204 void
|
|
1205 gftp_lookup_request_option (gftp_request * request, char * key, void *value)
|
|
1206 {
|
143
|
1207 gftp_config_vars * tmpconfigvar;
|
|
1208
|
|
1209 if (request != NULL && request->local_options_hash != NULL &&
|
|
1210 (tmpconfigvar = g_hash_table_lookup (request->local_options_hash,
|
|
1211 key)) != NULL)
|
|
1212 memcpy (value, &tmpconfigvar->value, sizeof (value));
|
|
1213 else
|
|
1214 gftp_lookup_global_option (key, value);
|
122
|
1215 }
|
|
1216
|
|
1217
|
|
1218 void
|
227
|
1219 gftp_set_global_option (char * key, const void *value)
|
122
|
1220 {
|
227
|
1221 gftp_config_vars * tmpconfigvar, newconfigvar;
|
|
1222 void *nc_ptr;
|
|
1223 int ret;
|
129
|
1224
|
|
1225 if (gftp_global_options_htable != NULL &&
|
|
1226 (tmpconfigvar = g_hash_table_lookup (gftp_global_options_htable,
|
|
1227 key)) != NULL)
|
201
|
1228 {
|
227
|
1229 memcpy (&newconfigvar, tmpconfigvar, sizeof (newconfigvar));
|
|
1230
|
|
1231 /* Cheap warning fix for const pointer... */
|
|
1232 memcpy (&nc_ptr, &value, sizeof (nc_ptr));
|
|
1233 newconfigvar.value = nc_ptr;
|
|
1234 newconfigvar.flags &= ~GFTP_CVARS_FLAGS_DYNMEM;
|
201
|
1235
|
227
|
1236 ret = gftp_option_types[newconfigvar.otype].compare_function (&newconfigvar, tmpconfigvar);
|
|
1237 if (ret != 0)
|
|
1238 {
|
|
1239 gftp_option_types[newconfigvar.otype].copy_function (&newconfigvar, tmpconfigvar);
|
|
1240 gftp_configuration_changed = 1;
|
|
1241 }
|
201
|
1242 }
|
129
|
1243 else
|
|
1244 {
|
|
1245 fprintf (stderr, _("FATAL gFTP Error: Config option '%s' not found in global hash table\n"), key);
|
|
1246 exit (1);
|
|
1247 }
|
122
|
1248 }
|
|
1249
|
|
1250
|
|
1251 void
|
|
1252 gftp_set_request_option (gftp_request * request, char * key, void *value)
|
|
1253 {
|
136
|
1254 gftp_config_vars * tmpconfigvar;
|
|
1255
|
|
1256 if (request->local_options_hash == NULL)
|
|
1257 request->local_options_hash = g_hash_table_new (string_hash_function,
|
|
1258 string_hash_compare);
|
|
1259
|
|
1260 if ((tmpconfigvar = g_hash_table_lookup (request->local_options_hash,
|
|
1261 key)) != NULL)
|
143
|
1262 memcpy (&tmpconfigvar->value, &value, sizeof (tmpconfigvar->value));
|
136
|
1263 else
|
|
1264 {
|
143
|
1265 if (gftp_global_options_htable == NULL ||
|
136
|
1266 (tmpconfigvar = g_hash_table_lookup (gftp_global_options_htable,
|
|
1267 key)) == NULL)
|
|
1268 {
|
|
1269 fprintf (stderr, _("FATAL gFTP Error: Config option '%s' not found in global hash table\n"), key);
|
|
1270 exit (1);
|
|
1271 }
|
|
1272
|
|
1273 request->num_local_options_vars++;
|
|
1274 request->local_options_vars = g_realloc (request->local_options_vars,
|
199
|
1275 sizeof (gftp_config_vars) * request->num_local_options_vars);
|
136
|
1276
|
143
|
1277 memcpy (&request->local_options_vars[request->num_local_options_vars - 1],
|
136
|
1278 tmpconfigvar, sizeof (*tmpconfigvar));
|
143
|
1279 memcpy (&request->local_options_vars[request->num_local_options_vars - 1].value, &value, sizeof (value));
|
|
1280
|
|
1281 g_hash_table_insert (request->local_options_hash, request->local_options_vars[request->num_local_options_vars - 1].key, &request->local_options_vars[request->num_local_options_vars - 1]);
|
136
|
1282 }
|
122
|
1283 }
|
|
1284
|
|
1285
|
|
1286 void
|
|
1287 gftp_register_config_vars (gftp_config_vars * config_vars)
|
|
1288 {
|
|
1289 gftp_options_list = g_list_append (gftp_options_list, config_vars);
|
|
1290 gftp_setup_global_options (config_vars);
|
|
1291 }
|
|
1292
|
199
|
1293
|
|
1294 void
|
|
1295 gftp_copy_local_options (gftp_config_vars ** new_options_vars,
|
|
1296 GHashTable ** new_options_hash,
|
|
1297 gftp_config_vars * orig_options,
|
|
1298 int num_local_options_vars)
|
|
1299 {
|
|
1300 int i;
|
|
1301
|
|
1302 if (orig_options == NULL || num_local_options_vars == 0)
|
|
1303 {
|
|
1304 *new_options_vars = NULL;
|
|
1305 *new_options_hash = NULL;
|
|
1306 return;
|
|
1307 }
|
|
1308
|
|
1309 *new_options_hash = g_hash_table_new (string_hash_function,
|
|
1310 string_hash_compare);
|
|
1311
|
|
1312 *new_options_vars = g_malloc (sizeof (gftp_config_vars) * num_local_options_vars);
|
|
1313 memcpy (*new_options_vars, orig_options,
|
|
1314 sizeof (gftp_config_vars) * num_local_options_vars);
|
|
1315
|
|
1316 for (i=0; i<num_local_options_vars; i++)
|
|
1317 {
|
|
1318 g_hash_table_insert (*new_options_hash, (*new_options_vars)[i].key,
|
|
1319 &(*new_options_vars)[i]);
|
207
|
1320
|
|
1321 (*new_options_vars)[i].value = NULL;
|
|
1322 (*new_options_vars)[i].flags &= ~GFTP_CVARS_FLAGS_DYNMEM;
|
199
|
1323
|
207
|
1324 gftp_option_types[(*new_options_vars)[i].otype].copy_function (&(orig_options)[i], &(*new_options_vars)[i]);
|
199
|
1325 }
|
|
1326 }
|
|
1327
|
201
|
1328
|
|
1329 void
|
|
1330 gftp_config_free_options (gftp_config_vars * options_vars,
|
|
1331 GHashTable * options_hash,
|
|
1332 int num_options_vars)
|
|
1333 {
|
|
1334 int i;
|
|
1335
|
|
1336 if (num_options_vars == 0)
|
|
1337 return;
|
|
1338
|
|
1339 if (num_options_vars > 0)
|
|
1340 {
|
|
1341 /* If num_options_vars is 0, then the options was allocated with malloc */
|
|
1342
|
|
1343 for (i=0; i<num_options_vars; i++)
|
|
1344 {
|
|
1345 if (options_vars[i].flags & GFTP_CVARS_FLAGS_DYNMEM &&
|
|
1346 options_vars[i].value != NULL)
|
|
1347 g_free (options_vars[i].value);
|
|
1348 }
|
|
1349
|
|
1350 g_free (options_vars);
|
|
1351 }
|
|
1352 else if (num_options_vars < 0)
|
|
1353 {
|
|
1354 /* Otherwise we are freeing the global options */
|
|
1355
|
|
1356 for (i=0; options_vars[i].key != NULL; i++)
|
|
1357 {
|
|
1358 if (options_vars[i].flags & GFTP_CVARS_FLAGS_DYNMEM &&
|
|
1359 options_vars[i].value != NULL)
|
|
1360 g_free (options_vars[i].value);
|
|
1361
|
|
1362 if (options_vars[i].flags & GFTP_CVARS_FLAGS_DYNLISTMEM &&
|
|
1363 options_vars[i].listdata != NULL)
|
|
1364 g_free (options_vars[i].listdata);
|
|
1365 }
|
|
1366 }
|
|
1367
|
|
1368 if (options_hash != NULL)
|
|
1369 g_hash_table_destroy (options_hash);
|
|
1370 }
|
|
1371
|
|
1372
|
|
1373 void
|
|
1374 gftp_bookmarks_destroy (gftp_bookmarks_var * bookmarks)
|
|
1375 {
|
|
1376 gftp_bookmarks_var * tempentry, * delentry;
|
|
1377
|
|
1378 if (bookmarks == NULL)
|
|
1379 return;
|
|
1380
|
|
1381 tempentry = bookmarks;
|
|
1382 while (tempentry != NULL)
|
|
1383 {
|
|
1384 gftp_free_bookmark (tempentry);
|
227
|
1385
|
|
1386 if (tempentry->path != NULL)
|
|
1387 g_free (tempentry->path);
|
201
|
1388
|
|
1389 if (tempentry->children != NULL)
|
|
1390 {
|
|
1391 tempentry = tempentry->children;
|
|
1392 continue;
|
|
1393 }
|
|
1394
|
|
1395 while (tempentry->next == NULL && tempentry->prev != NULL)
|
|
1396 {
|
|
1397 delentry = tempentry;
|
|
1398 tempentry = tempentry->prev;
|
|
1399 g_free (delentry);
|
|
1400 }
|
|
1401
|
|
1402 delentry = tempentry;
|
|
1403 tempentry = tempentry->next;
|
|
1404 g_free (delentry);
|
|
1405 }
|
|
1406 }
|
|
1407
|
218
|
1408
|
|
1409 void
|
|
1410 gftp_free_proxy_hosts (GList * proxy_hosts)
|
|
1411 {
|
|
1412 gftp_proxy_hosts * hosts;
|
|
1413 GList * templist;
|
|
1414
|
|
1415 for (templist = proxy_hosts;
|
|
1416 templist != NULL;
|
|
1417 templist = templist->next)
|
|
1418 {
|
|
1419 hosts = templist->data;
|
|
1420
|
|
1421 if (hosts->domain)
|
|
1422 g_free (hosts->domain);
|
|
1423 g_free (hosts);
|
|
1424 }
|
|
1425
|
|
1426 g_list_free (proxy_hosts);
|
|
1427 }
|
|
1428
|
|
1429
|
|
1430 GList *
|
|
1431 gftp_copy_proxy_hosts (GList * proxy_hosts)
|
|
1432 {
|
|
1433 gftp_proxy_hosts * oldhosts, * newhosts;
|
|
1434 GList * templist, * new_proxy_hosts;
|
|
1435
|
|
1436 new_proxy_hosts = NULL;
|
|
1437
|
|
1438 if (proxy_hosts != NULL)
|
|
1439 {
|
|
1440 for (templist = proxy_hosts;
|
|
1441 templist != NULL;
|
|
1442 templist = templist->next)
|
|
1443 {
|
|
1444 oldhosts = templist->data;
|
|
1445
|
|
1446 newhosts = g_malloc0 (sizeof (*newhosts));
|
|
1447 memcpy (newhosts, oldhosts, sizeof (*newhosts));
|
|
1448
|
|
1449 if (oldhosts->domain)
|
|
1450 newhosts->domain = g_strdup (oldhosts->domain);
|
|
1451
|
|
1452 new_proxy_hosts = g_list_append (new_proxy_hosts, newhosts);
|
|
1453 }
|
|
1454 }
|
|
1455
|
|
1456 return (new_proxy_hosts);
|
|
1457 }
|
|
1458
|