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
|
|
787 for (i=0; gftp_config_list[i].list != NULL; i++)
|
|
788 {
|
|
789 fprintf (conffile, "\n");
|
|
790 if (gftp_config_list[i].header != NULL)
|
|
791 write_comment (conffile, _(gftp_config_list[i].header));
|
|
792
|
|
793 for (templist = gftp_options_list;
|
|
794 templist != NULL;
|
|
795 templist = templist->next)
|
|
796 {
|
|
797 fprintf (conffile, "%s=", gftp_config_list[i].key);
|
|
798 gftp_config_list[i].write_func (conffile, templist->data);
|
|
799 fprintf (conffile, "\n");
|
|
800 }
|
|
801 }
|
|
802
|
|
803 fclose (conffile);
|
|
804 }
|
|
805
|
|
806
|
1
|
807 GHashTable *
|
122
|
808 build_bookmarks_hash_table (gftp_bookmarks_var * entry)
|
1
|
809 {
|
122
|
810 gftp_bookmarks_var * tempentry;
|
1
|
811 GHashTable * htable;
|
|
812
|
|
813 htable = g_hash_table_new (string_hash_function, string_hash_compare);
|
|
814 tempentry = entry;
|
|
815 while (tempentry != NULL)
|
|
816 {
|
|
817 g_hash_table_insert (htable, tempentry->path, tempentry);
|
|
818 if (tempentry->children != NULL)
|
|
819 {
|
|
820 tempentry = tempentry->children;
|
|
821 continue;
|
|
822 }
|
|
823 while (tempentry->next == NULL && tempentry->prev != NULL)
|
|
824 tempentry = tempentry->prev;
|
|
825 tempentry = tempentry->next;
|
|
826 }
|
|
827 return (htable);
|
|
828 }
|
|
829
|
|
830
|
|
831 void
|
122
|
832 print_bookmarks (gftp_bookmarks_var * bookmarks)
|
1
|
833 {
|
122
|
834 gftp_bookmarks_var * tempentry;
|
1
|
835
|
|
836 tempentry = bookmarks->children;
|
|
837 while (tempentry != NULL)
|
|
838 {
|
|
839 printf ("Path: %s (%d)\n", tempentry->path, tempentry->children != NULL);
|
|
840 if (tempentry->children != NULL)
|
|
841 {
|
|
842 tempentry = tempentry->children;
|
|
843 continue;
|
|
844 }
|
|
845
|
|
846 if (tempentry->next == NULL)
|
|
847 {
|
|
848 while (tempentry->next == NULL && tempentry->prev != NULL)
|
|
849 tempentry = tempentry->prev;
|
|
850 tempentry = tempentry->next;
|
|
851 }
|
|
852 else
|
|
853 tempentry = tempentry->next;
|
|
854 }
|
|
855 }
|
|
856
|
122
|
857
|
|
858 static int
|
|
859 gftp_config_file_read_text (char *str, gftp_config_vars * cv, int line)
|
|
860 {
|
136
|
861 if (cv->flags & GFTP_CVARS_FLAGS_DYNMEM && cv->value != NULL)
|
|
862 g_free (cv->value);
|
|
863
|
122
|
864 if (str != NULL)
|
|
865 {
|
|
866 cv->value = g_strdup (str);
|
136
|
867 cv->flags |= GFTP_CVARS_FLAGS_DYNMEM;
|
122
|
868 return (0);
|
|
869 }
|
|
870 else
|
136
|
871 {
|
|
872 cv->value = NULL;
|
|
873 cv->flags &= ~GFTP_CVARS_FLAGS_DYNMEM;
|
|
874 return (-1);
|
|
875 }
|
122
|
876 }
|
|
877
|
|
878
|
|
879 static int
|
|
880 gftp_config_file_write_text (gftp_config_vars * cv, FILE * fd, int to_config_file)
|
|
881 {
|
|
882 char *outstr;
|
|
883
|
|
884 if (cv->value != NULL)
|
|
885 {
|
|
886 outstr = cv->value;
|
|
887 if (*outstr != '\0')
|
|
888 fprintf (fd, "%s", outstr);
|
|
889 return (0);
|
|
890 }
|
|
891 else
|
|
892 return (-1);
|
|
893 }
|
|
894
|
|
895
|
|
896 static int
|
|
897 gftp_config_file_write_hidetext (gftp_config_vars * cv, FILE * fd, int to_config_file)
|
|
898 {
|
|
899 char *outstr;
|
|
900
|
|
901 if (cv->value != NULL)
|
|
902 {
|
|
903 outstr = cv->value;
|
|
904 if (*outstr != '\0')
|
|
905 {
|
|
906 if (to_config_file)
|
|
907 fprintf (fd, "%s", outstr);
|
|
908 else
|
|
909 fprintf (fd, "*****");
|
|
910 }
|
|
911 return (0);
|
|
912 }
|
|
913 else
|
|
914 return (-1);
|
|
915 }
|
|
916
|
|
917
|
207
|
918 static void
|
|
919 gftp_config_file_copy_text (gftp_config_vars * cv, gftp_config_vars * dest_cv)
|
|
920 {
|
|
921 if (dest_cv->flags & GFTP_CVARS_FLAGS_DYNMEM && dest_cv->value != NULL)
|
|
922 g_free (dest_cv->value);
|
|
923
|
|
924 if (cv->value != NULL)
|
|
925 {
|
|
926 dest_cv->value = g_strdup ((char *) cv->value);
|
|
927 dest_cv->flags |= GFTP_CVARS_FLAGS_DYNMEM;
|
|
928 }
|
|
929 else
|
|
930 dest_cv->value = NULL;
|
|
931 }
|
|
932
|
|
933
|
|
934 static void
|
|
935 gftp_config_file_copy_ptr_contents (gftp_config_vars * cv, gftp_config_vars * dest_cv)
|
|
936 {
|
|
937 memcpy (&dest_cv->value, &cv->value, sizeof (dest_cv->value));
|
|
938 }
|
|
939
|
122
|
940 static int
|
|
941 gftp_config_file_read_int (char *str, gftp_config_vars * cv, int line)
|
|
942 {
|
|
943 cv->value = GINT_TO_POINTER(strtol (str, NULL, 10));
|
|
944 return (0);
|
|
945 }
|
|
946
|
|
947
|
|
948 static int
|
|
949 gftp_config_file_write_int (gftp_config_vars * cv, FILE * fd, int to_config_file)
|
|
950 {
|
|
951 fprintf (fd, "%d", GPOINTER_TO_INT(cv->value));
|
|
952 return (0);
|
|
953 }
|
|
954
|
|
955
|
|
956 static int
|
|
957 gftp_config_file_read_checkbox (char *str, gftp_config_vars * cv, int line)
|
|
958 {
|
|
959 cv->value = GINT_TO_POINTER(strtol (str, NULL, 10) ? 1 : 0);
|
|
960 return (0);
|
|
961 }
|
|
962
|
|
963
|
|
964 static int
|
|
965 gftp_config_file_read_float (char *str, gftp_config_vars * cv, int line)
|
|
966 {
|
131
|
967 float f;
|
|
968
|
151
|
969 f = strtod (str, NULL);
|
131
|
970 memcpy (&cv->value, &f, sizeof (cv->value));
|
122
|
971 return (0);
|
|
972 }
|
|
973
|
|
974
|
|
975 static int
|
|
976 gftp_config_file_write_float (gftp_config_vars * cv, FILE * fd, int to_config_file)
|
|
977 {
|
131
|
978 float f;
|
|
979
|
|
980 memcpy (&f, &cv->value, sizeof (f));
|
|
981 fprintf (fd, "%.2f", f);
|
122
|
982 return (0);
|
|
983 }
|
|
984
|
|
985
|
|
986 static int
|
|
987 gftp_config_file_read_color (char *str, gftp_config_vars * cv, int line)
|
|
988 {
|
|
989 char *red, *green, *blue;
|
|
990 gftp_color * color;
|
|
991
|
136
|
992 if (cv->flags & GFTP_CVARS_FLAGS_DYNMEM && cv->value != NULL)
|
|
993 g_free (cv->value);
|
|
994
|
198
|
995 gftp_config_parse_args (str, 3, line, &red, &green, &blue);
|
122
|
996
|
|
997 color = g_malloc (sizeof (*color));
|
|
998 color->red = strtol (red, NULL, 16);
|
|
999 color->green = strtol (green, NULL, 16);
|
|
1000 color->blue = strtol (blue, NULL, 16);
|
|
1001 g_free (red);
|
|
1002 g_free (green);
|
|
1003 g_free (blue);
|
|
1004
|
|
1005 cv->value = color;
|
136
|
1006 cv->flags |= GFTP_CVARS_FLAGS_DYNMEM;
|
122
|
1007
|
|
1008 return (0);
|
|
1009 }
|
|
1010
|
|
1011
|
|
1012 static int
|
|
1013 gftp_config_file_write_color (gftp_config_vars * cv, FILE * fd, int to_config_file)
|
|
1014 {
|
|
1015 gftp_color * color;
|
|
1016
|
|
1017 color = cv->value;
|
|
1018 fprintf (fd, "%x:%x:%x", color->red, color->green, color->blue);
|
|
1019 return (0);
|
|
1020 }
|
|
1021
|
|
1022
|
207
|
1023 static void
|
|
1024 gftp_config_file_copy_color (gftp_config_vars * cv, gftp_config_vars * dest_cv)
|
|
1025 {
|
|
1026 if (dest_cv->flags & GFTP_CVARS_FLAGS_DYNMEM && dest_cv->value != NULL)
|
|
1027 g_free (dest_cv->value);
|
|
1028
|
|
1029 dest_cv->value = g_malloc (sizeof (gftp_color));
|
|
1030 memcpy (dest_cv->value, cv->value, sizeof (gftp_color));
|
|
1031 dest_cv->flags |= GFTP_CVARS_FLAGS_DYNMEM;
|
|
1032 }
|
|
1033
|
|
1034
|
122
|
1035 static int
|
|
1036 gftp_config_file_read_intcombo (char *str, gftp_config_vars * cv, int line)
|
|
1037 {
|
|
1038 char **clist;
|
|
1039 int i;
|
|
1040
|
|
1041 cv->value = 0;
|
|
1042 if (cv->listdata != NULL)
|
|
1043 {
|
|
1044 clist = cv->listdata;
|
|
1045 for (i=0; clist[i] != NULL; i++)
|
|
1046 {
|
125
|
1047 if (strcasecmp (clist[i], str) == 0)
|
122
|
1048 {
|
|
1049 cv->value = GINT_TO_POINTER(i);
|
|
1050 break;
|
|
1051 }
|
|
1052 }
|
|
1053 }
|
|
1054
|
|
1055 return (0);
|
|
1056 }
|
|
1057
|
|
1058
|
|
1059 static int
|
|
1060 gftp_config_file_write_intcombo (gftp_config_vars * cv, FILE * fd, int to_config_file)
|
|
1061 {
|
|
1062 char **clist;
|
|
1063
|
|
1064 clist = cv->listdata;
|
|
1065 if (clist != NULL)
|
125
|
1066 fprintf (fd, "%s", clist[GPOINTER_TO_INT(cv->value)]);
|
122
|
1067 else
|
|
1068 fprintf (fd, _("<unknown>"));
|
|
1069
|
|
1070 return (0);
|
|
1071 }
|
|
1072
|
|
1073
|
125
|
1074 static int
|
|
1075 gftp_config_file_read_textcombo (char *str, gftp_config_vars * cv, int line)
|
|
1076 {
|
|
1077 char **clist;
|
|
1078 int i;
|
|
1079
|
|
1080 cv->value = NULL;
|
|
1081 if (cv->listdata != NULL)
|
|
1082 {
|
|
1083 clist = cv->listdata;
|
|
1084 for (i=0; clist[i] != NULL; i++)
|
|
1085 {
|
|
1086 if (strcasecmp (clist[i], str) == 0)
|
|
1087 {
|
|
1088 cv->value = clist[i];
|
|
1089 break;
|
|
1090 }
|
|
1091 }
|
|
1092 }
|
|
1093
|
|
1094 return (0);
|
|
1095 }
|
|
1096
|
|
1097
|
|
1098 /* Note, the index numbers of this array must match up to the numbers in
|
122
|
1099 gftp_option_type_enum in gftp.h */
|
|
1100 gftp_option_type_var gftp_option_types[] = {
|
207
|
1101 {gftp_config_file_read_text, gftp_config_file_write_text, gftp_config_file_copy_text, NULL, NULL, NULL},
|
|
1102 {gftp_config_file_read_textcombo, gftp_config_file_write_text, gftp_config_file_copy_text, NULL, NULL, NULL},
|
|
1103 {gftp_config_file_read_text, gftp_config_file_write_text, gftp_config_file_copy_text, NULL, NULL, NULL},
|
|
1104 {gftp_config_file_read_text, gftp_config_file_write_hidetext, gftp_config_file_copy_text, NULL, NULL, NULL},
|
|
1105 {gftp_config_file_read_int, gftp_config_file_write_int, gftp_config_file_copy_ptr_contents, NULL, NULL, NULL},
|
|
1106 {gftp_config_file_read_checkbox, gftp_config_file_write_int, gftp_config_file_copy_ptr_contents, NULL, NULL, NULL},
|
|
1107 {gftp_config_file_read_intcombo, gftp_config_file_write_intcombo, gftp_config_file_copy_ptr_contents, NULL, NULL, NULL},
|
|
1108 {gftp_config_file_read_float, gftp_config_file_write_float, gftp_config_file_copy_ptr_contents, NULL, NULL, NULL},
|
|
1109 {gftp_config_file_read_color, gftp_config_file_write_color, gftp_config_file_copy_color, NULL, NULL, NULL},
|
136
|
1110 {NULL, NULL, NULL, NULL, NULL},
|
|
1111 {NULL, NULL, NULL, NULL, NULL}
|
122
|
1112 };
|
|
1113
|
|
1114
|
|
1115 void
|
|
1116 gftp_lookup_global_option (char * key, void *value)
|
|
1117 {
|
|
1118 gftp_config_list_vars * tmplistvar;
|
|
1119 gftp_config_vars * tmpconfigvar;
|
|
1120
|
|
1121 if (gftp_global_options_htable != NULL &&
|
|
1122 (tmpconfigvar = g_hash_table_lookup (gftp_global_options_htable,
|
|
1123 key)) != NULL)
|
124
|
1124 memcpy (value, &tmpconfigvar->value, sizeof (value));
|
122
|
1125 else if ((tmplistvar = g_hash_table_lookup (gftp_config_list_htable,
|
|
1126 key)) != NULL)
|
124
|
1127 *(gftp_config_list_vars **) value = tmplistvar;
|
122
|
1128 else
|
|
1129 {
|
|
1130 fprintf (stderr, _("FATAL gFTP Error: Config option '%s' not found in global hash table\n"), key);
|
|
1131 exit (1);
|
|
1132 }
|
|
1133 }
|
|
1134
|
|
1135
|
|
1136 void
|
|
1137 gftp_lookup_request_option (gftp_request * request, char * key, void *value)
|
|
1138 {
|
143
|
1139 gftp_config_vars * tmpconfigvar;
|
|
1140
|
|
1141 if (request != NULL && request->local_options_hash != NULL &&
|
|
1142 (tmpconfigvar = g_hash_table_lookup (request->local_options_hash,
|
|
1143 key)) != NULL)
|
|
1144 memcpy (value, &tmpconfigvar->value, sizeof (value));
|
|
1145 else
|
|
1146 gftp_lookup_global_option (key, value);
|
122
|
1147 }
|
|
1148
|
|
1149
|
|
1150 void
|
|
1151 gftp_set_global_option (char * key, void *value)
|
|
1152 {
|
129
|
1153 gftp_config_vars * tmpconfigvar;
|
|
1154
|
|
1155 if (gftp_global_options_htable != NULL &&
|
|
1156 (tmpconfigvar = g_hash_table_lookup (gftp_global_options_htable,
|
|
1157 key)) != NULL)
|
201
|
1158 {
|
|
1159 memcpy (&tmpconfigvar->value, value, sizeof (tmpconfigvar->value));
|
|
1160
|
|
1161 /* FIXME - only set this variable if the value has changed */
|
|
1162 gftp_configuration_changed = 1;
|
|
1163 }
|
129
|
1164 else
|
|
1165 {
|
|
1166 fprintf (stderr, _("FATAL gFTP Error: Config option '%s' not found in global hash table\n"), key);
|
|
1167 exit (1);
|
|
1168 }
|
122
|
1169 }
|
|
1170
|
|
1171
|
|
1172 void
|
|
1173 gftp_set_request_option (gftp_request * request, char * key, void *value)
|
|
1174 {
|
136
|
1175 gftp_config_vars * tmpconfigvar;
|
|
1176
|
|
1177 if (request->local_options_hash == NULL)
|
|
1178 request->local_options_hash = g_hash_table_new (string_hash_function,
|
|
1179 string_hash_compare);
|
|
1180
|
|
1181 if ((tmpconfigvar = g_hash_table_lookup (request->local_options_hash,
|
|
1182 key)) != NULL)
|
143
|
1183 memcpy (&tmpconfigvar->value, &value, sizeof (tmpconfigvar->value));
|
136
|
1184 else
|
|
1185 {
|
143
|
1186 if (gftp_global_options_htable == NULL ||
|
136
|
1187 (tmpconfigvar = g_hash_table_lookup (gftp_global_options_htable,
|
|
1188 key)) == NULL)
|
|
1189 {
|
|
1190 fprintf (stderr, _("FATAL gFTP Error: Config option '%s' not found in global hash table\n"), key);
|
|
1191 exit (1);
|
|
1192 }
|
|
1193
|
|
1194 request->num_local_options_vars++;
|
|
1195 request->local_options_vars = g_realloc (request->local_options_vars,
|
199
|
1196 sizeof (gftp_config_vars) * request->num_local_options_vars);
|
136
|
1197
|
143
|
1198 memcpy (&request->local_options_vars[request->num_local_options_vars - 1],
|
136
|
1199 tmpconfigvar, sizeof (*tmpconfigvar));
|
143
|
1200 memcpy (&request->local_options_vars[request->num_local_options_vars - 1].value, &value, sizeof (value));
|
|
1201
|
|
1202 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
|
1203 }
|
122
|
1204 }
|
|
1205
|
|
1206
|
|
1207 void
|
|
1208 gftp_register_config_vars (gftp_config_vars * config_vars)
|
|
1209 {
|
|
1210 gftp_options_list = g_list_append (gftp_options_list, config_vars);
|
|
1211 gftp_setup_global_options (config_vars);
|
|
1212 }
|
|
1213
|
199
|
1214
|
|
1215 void
|
|
1216 gftp_copy_local_options (gftp_config_vars ** new_options_vars,
|
|
1217 GHashTable ** new_options_hash,
|
|
1218 gftp_config_vars * orig_options,
|
|
1219 int num_local_options_vars)
|
|
1220 {
|
|
1221 int i;
|
|
1222
|
|
1223 if (orig_options == NULL || num_local_options_vars == 0)
|
|
1224 {
|
|
1225 *new_options_vars = NULL;
|
|
1226 *new_options_hash = NULL;
|
|
1227 return;
|
|
1228 }
|
|
1229
|
|
1230 *new_options_hash = g_hash_table_new (string_hash_function,
|
|
1231 string_hash_compare);
|
|
1232
|
|
1233 *new_options_vars = g_malloc (sizeof (gftp_config_vars) * num_local_options_vars);
|
|
1234 memcpy (*new_options_vars, orig_options,
|
|
1235 sizeof (gftp_config_vars) * num_local_options_vars);
|
|
1236
|
|
1237 for (i=0; i<num_local_options_vars; i++)
|
|
1238 {
|
|
1239 g_hash_table_insert (*new_options_hash, (*new_options_vars)[i].key,
|
|
1240 &(*new_options_vars)[i]);
|
207
|
1241
|
|
1242 (*new_options_vars)[i].value = NULL;
|
|
1243 (*new_options_vars)[i].flags &= ~GFTP_CVARS_FLAGS_DYNMEM;
|
199
|
1244
|
207
|
1245 gftp_option_types[(*new_options_vars)[i].otype].copy_function (&(orig_options)[i], &(*new_options_vars)[i]);
|
199
|
1246 }
|
|
1247 }
|
|
1248
|
201
|
1249
|
|
1250 void
|
|
1251 gftp_config_free_options (gftp_config_vars * options_vars,
|
|
1252 GHashTable * options_hash,
|
|
1253 int num_options_vars)
|
|
1254 {
|
|
1255 int i;
|
|
1256
|
|
1257 if (num_options_vars == 0)
|
|
1258 return;
|
|
1259
|
|
1260 if (num_options_vars > 0)
|
|
1261 {
|
|
1262 /* If num_options_vars is 0, then the options was allocated with malloc */
|
|
1263
|
|
1264 for (i=0; i<num_options_vars; i++)
|
|
1265 {
|
|
1266 if (options_vars[i].flags & GFTP_CVARS_FLAGS_DYNMEM &&
|
|
1267 options_vars[i].value != NULL)
|
|
1268 g_free (options_vars[i].value);
|
|
1269 }
|
|
1270
|
|
1271 g_free (options_vars);
|
|
1272 }
|
|
1273 else if (num_options_vars < 0)
|
|
1274 {
|
|
1275 /* Otherwise we are freeing the global options */
|
|
1276
|
|
1277 for (i=0; options_vars[i].key != NULL; i++)
|
|
1278 {
|
|
1279 if (options_vars[i].flags & GFTP_CVARS_FLAGS_DYNMEM &&
|
|
1280 options_vars[i].value != NULL)
|
|
1281 g_free (options_vars[i].value);
|
|
1282
|
|
1283 if (options_vars[i].flags & GFTP_CVARS_FLAGS_DYNLISTMEM &&
|
|
1284 options_vars[i].listdata != NULL)
|
|
1285 g_free (options_vars[i].listdata);
|
|
1286 }
|
|
1287 }
|
|
1288
|
|
1289 if (options_hash != NULL)
|
|
1290 g_hash_table_destroy (options_hash);
|
|
1291 }
|
|
1292
|
|
1293
|
|
1294 void
|
|
1295 gftp_bookmarks_destroy (gftp_bookmarks_var * bookmarks)
|
|
1296 {
|
|
1297 gftp_bookmarks_var * tempentry, * delentry;
|
|
1298
|
|
1299 if (bookmarks == NULL)
|
|
1300 return;
|
|
1301
|
|
1302 tempentry = bookmarks;
|
|
1303 while (tempentry != NULL)
|
|
1304 {
|
|
1305 gftp_free_bookmark (tempentry);
|
|
1306 g_free (tempentry->path);
|
|
1307
|
|
1308 if (tempentry->children != NULL)
|
|
1309 {
|
|
1310 tempentry = tempentry->children;
|
|
1311 continue;
|
|
1312 }
|
|
1313
|
|
1314 while (tempentry->next == NULL && tempentry->prev != NULL)
|
|
1315 {
|
|
1316 delentry = tempentry;
|
|
1317 tempentry = tempentry->prev;
|
|
1318 g_free (delentry);
|
|
1319 }
|
|
1320
|
|
1321 delentry = tempentry;
|
|
1322 tempentry = tempentry->next;
|
|
1323 g_free (delentry);
|
|
1324 }
|
207
|
1325
|
|
1326 g_free (bookmarks);
|
201
|
1327 }
|
|
1328
|