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 char *tempstr;
|
|
417
|
|
418 tempext = g_malloc (sizeof (*tempext));
|
198
|
419 gftp_config_parse_args (buf, 4, line, &tempext->ext, &tempext->filename,
|
|
420 &tempext->ascii_binary, &tempext->view_program);
|
122
|
421
|
|
422 if ((tempstr = get_xpm_path (tempext->filename, 1)) != NULL)
|
|
423 g_free (tempstr);
|
|
424
|
|
425 tempext->stlen = strlen (tempext->ext);
|
|
426
|
|
427 return (tempext);
|
|
428 }
|
|
429
|
|
430
|
|
431 static void
|
|
432 gftp_config_write_ext (FILE *fd, void *data)
|
|
433 {
|
|
434 gftp_file_extensions * tempext;
|
|
435
|
|
436 tempext = data;
|
|
437 fprintf (fd, "%s:%s:%c:%s", tempext->ext, tempext->filename,
|
|
438 *tempext->ascii_binary == '\0' ? ' ' : *tempext->ascii_binary,
|
|
439 tempext->view_program);
|
|
440 }
|
|
441
|
|
442
|
|
443 gftp_config_list_vars gftp_config_list[] = {
|
|
444 {"dont_use_proxy", gftp_config_read_proxy, gftp_config_write_proxy,
|
|
445 NULL, 0,
|
|
446 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")},
|
|
447 {"ext", gftp_config_read_ext, gftp_config_write_ext,
|
|
448 NULL, 0,
|
|
449 N_("ext=file extenstion:XPM file:Ascii or Binary (A or B):viewer program. Note: All arguments except the file extension are optional")},
|
|
450 {"localhistory", gftp_config_read_str, gftp_config_write_str,
|
|
451 NULL, 0, NULL},
|
|
452 {"remotehistory", gftp_config_read_str, gftp_config_write_str,
|
|
453 NULL, 0, NULL},
|
|
454 {"hosthistory", gftp_config_read_str, gftp_config_write_str,
|
|
455 NULL, 0, NULL},
|
|
456 {"porthistory", gftp_config_read_str, gftp_config_write_str,
|
|
457 NULL, 0, NULL},
|
|
458 {"userhistory", gftp_config_read_str, gftp_config_write_str,
|
|
459 NULL, 0, NULL},
|
|
460 {NULL, NULL, NULL,
|
|
461 NULL, 0, NULL}
|
|
462 };
|
|
463
|
|
464
|
|
465 static void
|
|
466 gftp_setup_global_options (gftp_config_vars * cvars)
|
|
467 {
|
|
468 int i;
|
|
469
|
|
470 for (i=0; cvars[i].key != NULL; i++)
|
|
471 {
|
136
|
472 if (cvars[i].key != NULL && *cvars[i].key != '\0')
|
122
|
473 g_hash_table_insert (gftp_global_options_htable,
|
|
474 cvars[i].key, &cvars[i]);
|
|
475 }
|
|
476 }
|
|
477
|
|
478
|
|
479 void
|
124
|
480 gftp_read_config_file (char *global_data_path)
|
122
|
481 {
|
|
482 char *tempstr, *temp1str, *curpos, buf[255];
|
|
483 gftp_config_list_vars * tmplistvar;
|
|
484 gftp_config_vars * tmpconfigvar;
|
125
|
485 char **protocol_list;
|
122
|
486 FILE *conffile;
|
|
487 int line, i;
|
|
488 size_t len;
|
|
489
|
|
490 gftp_global_options_htable = g_hash_table_new (string_hash_function,
|
|
491 string_hash_compare);
|
|
492
|
|
493 gftp_register_config_vars (gftp_global_config_vars);
|
|
494
|
125
|
495 protocol_list = NULL;
|
122
|
496 for (i=0; gftp_protocols[i].register_options != NULL; i++)
|
|
497 {
|
125
|
498 if (gftp_protocols[i].shown)
|
|
499 {
|
|
500 protocol_list = g_realloc (protocol_list, sizeof (char *) * (i + 2));
|
|
501 protocol_list[i] = gftp_protocols[i].name;
|
|
502 protocol_list[i + 1] = NULL;
|
|
503 }
|
|
504
|
122
|
505 if (gftp_protocols[i].register_options != NULL)
|
|
506 gftp_protocols[i].register_options ();
|
|
507 }
|
|
508
|
125
|
509 if ((tmpconfigvar = g_hash_table_lookup (gftp_global_options_htable,
|
|
510 "default_protocol")) != NULL)
|
|
511 tmpconfigvar->listdata = protocol_list;
|
|
512
|
122
|
513 gftp_config_list_htable = g_hash_table_new (string_hash_function,
|
|
514 string_hash_compare);
|
|
515
|
|
516 for (i=0; gftp_config_list[i].key != NULL; i++)
|
|
517 {
|
|
518 g_hash_table_insert (gftp_config_list_htable, gftp_config_list[i].key,
|
|
519 &gftp_config_list[i]);
|
|
520 }
|
|
521
|
|
522 if ((tempstr = expand_path (CONFIG_FILE)) == NULL)
|
|
523 {
|
|
524 printf (_("gFTP Error: Bad config file name %s\n"), CONFIG_FILE);
|
|
525 exit (1);
|
|
526 }
|
|
527
|
|
528 if (access (tempstr, F_OK) == -1)
|
|
529 {
|
|
530 temp1str = expand_path (BASE_CONF_DIR);
|
|
531 if (access (temp1str, F_OK) == -1)
|
|
532 {
|
|
533 if (mkdir (temp1str, S_IRUSR | S_IWUSR | S_IXUSR) != 0)
|
|
534 {
|
|
535 printf (_("gFTP Error: Could not make directory %s: %s\n"),
|
|
536 temp1str, g_strerror (errno));
|
|
537 exit (1);
|
|
538 }
|
|
539 }
|
|
540 g_free (temp1str);
|
|
541
|
124
|
542 temp1str = g_strdup_printf ("%s/gftprc", global_data_path);
|
122
|
543 if (access (temp1str, F_OK) == -1)
|
|
544 {
|
|
545 printf (_("gFTP Error: Cannot find master config file %s\n"),
|
|
546 temp1str);
|
|
547 printf (_("Did you do a make install?\n"));
|
|
548 exit (1);
|
|
549 }
|
|
550 copyfile (temp1str, tempstr);
|
|
551 g_free (temp1str);
|
|
552 }
|
|
553
|
|
554 if ((conffile = fopen (tempstr, "r")) == NULL)
|
|
555 {
|
|
556 printf (_("gFTP Error: Cannot open config file %s: %s\n"), CONFIG_FILE,
|
|
557 g_strerror (errno));
|
|
558 exit (1);
|
|
559 }
|
|
560 g_free (tempstr);
|
|
561
|
|
562 line = 0;
|
|
563 while (fgets (buf, sizeof (buf), conffile))
|
|
564 {
|
|
565 len = strlen (buf);
|
|
566 if (len > 0 && buf[len - 1] == '\n')
|
|
567 buf[--len] = '\0';
|
|
568 if (len > 0 && buf[len - 1] == '\r')
|
|
569 buf[--len] = '\0';
|
|
570 line++;
|
|
571
|
|
572 if (*buf == '#' || *buf == '\0')
|
|
573 continue;
|
|
574
|
|
575 if ((curpos = strchr (buf, '=')) == NULL)
|
|
576 continue;
|
|
577
|
|
578 *curpos = '\0';
|
|
579
|
|
580 if ((tmplistvar = g_hash_table_lookup (gftp_config_list_htable,
|
|
581 buf)) != NULL)
|
|
582 {
|
|
583 tmplistvar->list = g_list_append (tmplistvar->list,
|
|
584 tmplistvar->read_func (curpos + 1,
|
|
585 line));
|
|
586 tmplistvar->num_items++;
|
|
587 }
|
|
588 else if ((tmpconfigvar = g_hash_table_lookup (gftp_global_options_htable,
|
|
589 buf)) != NULL &&
|
|
590 gftp_option_types[tmpconfigvar->otype].read_function != NULL)
|
|
591 {
|
|
592 if (gftp_option_types[tmpconfigvar->otype].read_function (curpos + 1,
|
|
593 tmpconfigvar, line) != 0)
|
|
594 {
|
|
595 printf (_("Terminating due to parse errors at line %d in the config file\n"), line);
|
|
596 exit (1);
|
|
597 }
|
|
598 }
|
|
599 else
|
|
600 {
|
|
601 printf (_("gFTP Warning: Skipping line %d in config file: %s\n"),
|
|
602 line, buf);
|
|
603 }
|
|
604 }
|
|
605
|
|
606 if ((tempstr = expand_path (LOG_FILE)) == NULL)
|
|
607 {
|
|
608 printf (_("gFTP Error: Bad log file name %s\n"), LOG_FILE);
|
|
609 exit (1);
|
|
610 }
|
|
611
|
|
612 if ((gftp_logfd = fopen (tempstr, "w")) == NULL)
|
|
613 {
|
|
614 printf (_("gFTP Warning: Cannot open %s for writing: %s\n"),
|
|
615 tempstr, g_strerror (errno));
|
|
616 }
|
|
617 g_free (tempstr);
|
|
618
|
|
619 gftp_bookmarks = g_malloc0 (sizeof (*gftp_bookmarks));
|
|
620 gftp_bookmarks->isfolder = 1;
|
|
621 gftp_bookmarks->path = g_malloc0 (1);
|
|
622 gftp_bookmarks_htable = g_hash_table_new (string_hash_function, string_hash_compare);
|
|
623
|
124
|
624 gftp_read_bookmarks (global_data_path);
|
122
|
625 }
|
|
626
|
|
627
|
|
628 static void
|
|
629 write_comment (FILE * fd, const char *comment)
|
|
630 {
|
|
631 const char *pos, *endpos;
|
|
632
|
|
633 fwrite ("# ", 1, 2, fd);
|
|
634 pos = comment;
|
|
635 while (strlen (pos) > 76)
|
|
636 {
|
|
637 for (endpos = pos + 76; *endpos != ' ' && endpos > pos; endpos--);
|
|
638 if (endpos == pos)
|
|
639 {
|
|
640 for (endpos = pos + 76; *endpos != ' ' && *endpos != '\0';
|
|
641 endpos++);
|
|
642 }
|
|
643 fwrite (pos, 1, endpos - pos, fd);
|
|
644 fwrite ("\n# ", 1, 3, fd);
|
|
645 if (*endpos == '\0')
|
|
646 {
|
|
647 pos = endpos;
|
|
648 break;
|
|
649 }
|
|
650 else
|
|
651 pos = endpos + 1;
|
|
652 }
|
|
653 if (strlen (pos) > 1)
|
|
654 {
|
|
655 fwrite (pos, 1, strlen (pos), fd);
|
|
656 fwrite ("\n", 1, 1, fd);
|
|
657 }
|
|
658 }
|
|
659
|
|
660
|
|
661 void
|
|
662 gftp_write_bookmarks_file (void)
|
|
663 {
|
|
664 gftp_bookmarks_var * tempentry;
|
|
665 char *bmhdr, *tempstr;
|
|
666 FILE * bmfile;
|
199
|
667 int i;
|
122
|
668
|
|
669 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");
|
|
670
|
|
671 if ((tempstr = expand_path (BOOKMARKS_FILE)) == NULL)
|
|
672 {
|
|
673 printf (_("gFTP Error: Bad bookmarks file name %s\n"), CONFIG_FILE);
|
|
674 exit (1);
|
|
675 }
|
|
676
|
|
677 if ((bmfile = fopen (tempstr, "w+")) == NULL)
|
|
678 {
|
|
679 printf (_("gFTP Error: Cannot open bookmarks file %s: %s\n"),
|
|
680 CONFIG_FILE, g_strerror (errno));
|
|
681 exit (1);
|
|
682 }
|
|
683
|
|
684 g_free (tempstr);
|
|
685
|
|
686 write_comment (bmfile, _(bmhdr));
|
|
687 fwrite ("\n", 1, 1, bmfile);
|
|
688
|
|
689 tempentry = gftp_bookmarks->children;
|
|
690 while (tempentry != NULL)
|
|
691 {
|
|
692 if (tempentry->children != NULL)
|
|
693 {
|
|
694 tempentry = tempentry->children;
|
|
695 continue;
|
|
696 }
|
|
697 tempstr = tempentry->path;
|
|
698 while (*tempstr == '/')
|
|
699 tempstr++;
|
|
700 fprintf (bmfile,
|
|
701 "[%s]\nhostname=%s\nport=%d\nprotocol=%s\nremote directory=%s\nlocal directory=%s\nusername=%s\npassword=%s\naccount=%s\n",
|
|
702 tempstr, tempentry->hostname == NULL ? "" : tempentry->hostname,
|
|
703 tempentry->port, tempentry->protocol == NULL
|
|
704 || *tempentry->protocol ==
|
|
705 '\0' ? gftp_protocols[0].name : tempentry->protocol,
|
|
706 tempentry->remote_dir == NULL ? "" : tempentry->remote_dir,
|
|
707 tempentry->local_dir == NULL ? "" : tempentry->local_dir,
|
|
708 tempentry->user == NULL ? "" : tempentry->user,
|
|
709 !tempentry->save_password
|
|
710 || tempentry->pass == NULL ? "" : tempentry->pass,
|
|
711 tempentry->acct == NULL ? "" : tempentry->acct);
|
|
712
|
199
|
713 if (tempentry->local_options_vars != NULL)
|
|
714 {
|
|
715 for (i=0; i<tempentry->num_local_options_vars; i++)
|
|
716 {
|
|
717 fprintf (bmfile, "%s=", tempentry->local_options_vars[i].key);
|
|
718 gftp_option_types[tempentry->local_options_vars[i].otype].write_function (&tempentry->local_options_vars[i], bmfile, 1);
|
|
719 fprintf (bmfile, "\n");
|
|
720 }
|
|
721 }
|
122
|
722
|
|
723 fprintf (bmfile, "\n");
|
|
724
|
|
725 if (tempentry->next == NULL)
|
|
726 {
|
|
727 tempentry = tempentry->prev;
|
|
728 while (tempentry->next == NULL && tempentry->prev != NULL)
|
|
729 tempentry = tempentry->prev;
|
|
730 tempentry = tempentry->next;
|
|
731 }
|
|
732 else
|
|
733 tempentry = tempentry->next;
|
|
734 }
|
|
735
|
|
736 fclose (bmfile);
|
|
737 }
|
|
738
|
|
739
|
|
740 void
|
|
741 gftp_write_config_file (void)
|
|
742 {
|
|
743 gftp_config_vars * cv;
|
|
744 GList *templist;
|
|
745 FILE *conffile;
|
|
746 char *tempstr;
|
|
747 int i;
|
|
748
|
|
749 if ((tempstr = expand_path (CONFIG_FILE)) == NULL)
|
|
750 {
|
|
751 printf (_("gFTP Error: Bad config file name %s\n"), CONFIG_FILE);
|
|
752 exit (1);
|
|
753 }
|
|
754
|
|
755 if ((conffile = fopen (tempstr, "w+")) == NULL)
|
|
756 {
|
|
757 printf (_("gFTP Error: Cannot open config file %s: %s\n"), CONFIG_FILE,
|
|
758 g_strerror (errno));
|
|
759 exit (1);
|
|
760 }
|
|
761
|
|
762 g_free (tempstr);
|
|
763
|
|
764 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"));
|
|
765
|
|
766 for (templist = gftp_options_list;
|
|
767 templist != NULL;
|
|
768 templist = templist->next)
|
|
769 {
|
|
770 cv = templist->data;
|
|
771
|
|
772 for (i=0; cv[i].key != NULL; i++)
|
|
773 {
|
|
774 if (gftp_option_types[cv[i].otype].write_function == NULL ||
|
|
775 *cv[i].key == '\0')
|
|
776 continue;
|
|
777
|
|
778 fprintf (conffile, "\n");
|
|
779 if (cv[i].comment != NULL)
|
|
780 write_comment (conffile, _(cv[i].comment));
|
|
781
|
|
782 fprintf (conffile, "%s=", cv[i].key);
|
|
783 gftp_option_types[cv[i].otype].write_function (&cv[i], conffile, 1);
|
|
784 fprintf (conffile, "\n");
|
|
785 }
|
|
786 }
|
|
787
|
|
788 for (i=0; gftp_config_list[i].list != NULL; i++)
|
|
789 {
|
|
790 fprintf (conffile, "\n");
|
|
791 if (gftp_config_list[i].header != NULL)
|
|
792 write_comment (conffile, _(gftp_config_list[i].header));
|
|
793
|
|
794 for (templist = gftp_options_list;
|
|
795 templist != NULL;
|
|
796 templist = templist->next)
|
|
797 {
|
|
798 fprintf (conffile, "%s=", gftp_config_list[i].key);
|
|
799 gftp_config_list[i].write_func (conffile, templist->data);
|
|
800 fprintf (conffile, "\n");
|
|
801 }
|
|
802 }
|
|
803
|
|
804 fclose (conffile);
|
|
805 }
|
|
806
|
|
807
|
1
|
808 GHashTable *
|
122
|
809 build_bookmarks_hash_table (gftp_bookmarks_var * entry)
|
1
|
810 {
|
122
|
811 gftp_bookmarks_var * tempentry;
|
1
|
812 GHashTable * htable;
|
|
813
|
|
814 htable = g_hash_table_new (string_hash_function, string_hash_compare);
|
|
815 tempentry = entry;
|
|
816 while (tempentry != NULL)
|
|
817 {
|
|
818 g_hash_table_insert (htable, tempentry->path, tempentry);
|
|
819 if (tempentry->children != NULL)
|
|
820 {
|
|
821 tempentry = tempentry->children;
|
|
822 continue;
|
|
823 }
|
|
824 while (tempentry->next == NULL && tempentry->prev != NULL)
|
|
825 tempentry = tempentry->prev;
|
|
826 tempentry = tempentry->next;
|
|
827 }
|
|
828 return (htable);
|
|
829 }
|
|
830
|
|
831
|
|
832 void
|
122
|
833 print_bookmarks (gftp_bookmarks_var * bookmarks)
|
1
|
834 {
|
122
|
835 gftp_bookmarks_var * tempentry;
|
1
|
836
|
|
837 tempentry = bookmarks->children;
|
|
838 while (tempentry != NULL)
|
|
839 {
|
|
840 printf ("Path: %s (%d)\n", tempentry->path, tempentry->children != NULL);
|
|
841 if (tempentry->children != NULL)
|
|
842 {
|
|
843 tempentry = tempentry->children;
|
|
844 continue;
|
|
845 }
|
|
846
|
|
847 if (tempentry->next == NULL)
|
|
848 {
|
|
849 while (tempentry->next == NULL && tempentry->prev != NULL)
|
|
850 tempentry = tempentry->prev;
|
|
851 tempentry = tempentry->next;
|
|
852 }
|
|
853 else
|
|
854 tempentry = tempentry->next;
|
|
855 }
|
|
856 }
|
|
857
|
122
|
858
|
|
859 static int
|
|
860 gftp_config_file_read_text (char *str, gftp_config_vars * cv, int line)
|
|
861 {
|
136
|
862 if (cv->flags & GFTP_CVARS_FLAGS_DYNMEM && cv->value != NULL)
|
|
863 g_free (cv->value);
|
|
864
|
122
|
865 if (str != NULL)
|
|
866 {
|
|
867 cv->value = g_strdup (str);
|
136
|
868 cv->flags |= GFTP_CVARS_FLAGS_DYNMEM;
|
122
|
869 return (0);
|
|
870 }
|
|
871 else
|
136
|
872 {
|
|
873 cv->value = NULL;
|
|
874 cv->flags &= ~GFTP_CVARS_FLAGS_DYNMEM;
|
|
875 return (-1);
|
|
876 }
|
122
|
877 }
|
|
878
|
|
879
|
|
880 static int
|
|
881 gftp_config_file_write_text (gftp_config_vars * cv, FILE * fd, int to_config_file)
|
|
882 {
|
|
883 char *outstr;
|
|
884
|
|
885 if (cv->value != NULL)
|
|
886 {
|
|
887 outstr = cv->value;
|
|
888 if (*outstr != '\0')
|
|
889 fprintf (fd, "%s", outstr);
|
|
890 return (0);
|
|
891 }
|
|
892 else
|
|
893 return (-1);
|
|
894 }
|
|
895
|
|
896
|
|
897 static int
|
|
898 gftp_config_file_write_hidetext (gftp_config_vars * cv, FILE * fd, int to_config_file)
|
|
899 {
|
|
900 char *outstr;
|
|
901
|
|
902 if (cv->value != NULL)
|
|
903 {
|
|
904 outstr = cv->value;
|
|
905 if (*outstr != '\0')
|
|
906 {
|
|
907 if (to_config_file)
|
|
908 fprintf (fd, "%s", outstr);
|
|
909 else
|
|
910 fprintf (fd, "*****");
|
|
911 }
|
|
912 return (0);
|
|
913 }
|
|
914 else
|
|
915 return (-1);
|
|
916 }
|
|
917
|
|
918
|
|
919 static int
|
|
920 gftp_config_file_read_int (char *str, gftp_config_vars * cv, int line)
|
|
921 {
|
|
922 cv->value = GINT_TO_POINTER(strtol (str, NULL, 10));
|
|
923 return (0);
|
|
924 }
|
|
925
|
|
926
|
|
927 static int
|
|
928 gftp_config_file_write_int (gftp_config_vars * cv, FILE * fd, int to_config_file)
|
|
929 {
|
|
930 fprintf (fd, "%d", GPOINTER_TO_INT(cv->value));
|
|
931 return (0);
|
|
932 }
|
|
933
|
|
934
|
|
935 static int
|
|
936 gftp_config_file_read_checkbox (char *str, gftp_config_vars * cv, int line)
|
|
937 {
|
|
938 cv->value = GINT_TO_POINTER(strtol (str, NULL, 10) ? 1 : 0);
|
|
939 return (0);
|
|
940 }
|
|
941
|
|
942
|
|
943 static int
|
|
944 gftp_config_file_read_float (char *str, gftp_config_vars * cv, int line)
|
|
945 {
|
131
|
946 float f;
|
|
947
|
151
|
948 f = strtod (str, NULL);
|
131
|
949 memcpy (&cv->value, &f, sizeof (cv->value));
|
122
|
950 return (0);
|
|
951 }
|
|
952
|
|
953
|
|
954 static int
|
|
955 gftp_config_file_write_float (gftp_config_vars * cv, FILE * fd, int to_config_file)
|
|
956 {
|
131
|
957 float f;
|
|
958
|
|
959 memcpy (&f, &cv->value, sizeof (f));
|
|
960 fprintf (fd, "%.2f", f);
|
122
|
961 return (0);
|
|
962 }
|
|
963
|
|
964
|
|
965 static int
|
|
966 gftp_config_file_read_color (char *str, gftp_config_vars * cv, int line)
|
|
967 {
|
|
968 char *red, *green, *blue;
|
|
969 gftp_color * color;
|
|
970
|
136
|
971 if (cv->flags & GFTP_CVARS_FLAGS_DYNMEM && cv->value != NULL)
|
|
972 g_free (cv->value);
|
|
973
|
198
|
974 gftp_config_parse_args (str, 3, line, &red, &green, &blue);
|
122
|
975
|
|
976 color = g_malloc (sizeof (*color));
|
|
977 color->red = strtol (red, NULL, 16);
|
|
978 color->green = strtol (green, NULL, 16);
|
|
979 color->blue = strtol (blue, NULL, 16);
|
|
980 g_free (red);
|
|
981 g_free (green);
|
|
982 g_free (blue);
|
|
983
|
|
984 cv->value = color;
|
136
|
985 cv->flags |= GFTP_CVARS_FLAGS_DYNMEM;
|
122
|
986
|
|
987 return (0);
|
|
988 }
|
|
989
|
|
990
|
|
991 static int
|
|
992 gftp_config_file_write_color (gftp_config_vars * cv, FILE * fd, int to_config_file)
|
|
993 {
|
|
994 gftp_color * color;
|
|
995
|
|
996 color = cv->value;
|
|
997 fprintf (fd, "%x:%x:%x", color->red, color->green, color->blue);
|
|
998 return (0);
|
|
999 }
|
|
1000
|
|
1001
|
|
1002 static int
|
|
1003 gftp_config_file_read_intcombo (char *str, gftp_config_vars * cv, int line)
|
|
1004 {
|
|
1005 char **clist;
|
|
1006 int i;
|
|
1007
|
|
1008 cv->value = 0;
|
|
1009 if (cv->listdata != NULL)
|
|
1010 {
|
|
1011 clist = cv->listdata;
|
|
1012 for (i=0; clist[i] != NULL; i++)
|
|
1013 {
|
125
|
1014 if (strcasecmp (clist[i], str) == 0)
|
122
|
1015 {
|
|
1016 cv->value = GINT_TO_POINTER(i);
|
|
1017 break;
|
|
1018 }
|
|
1019 }
|
|
1020 }
|
|
1021
|
|
1022 return (0);
|
|
1023 }
|
|
1024
|
|
1025
|
|
1026 static int
|
|
1027 gftp_config_file_write_intcombo (gftp_config_vars * cv, FILE * fd, int to_config_file)
|
|
1028 {
|
|
1029 char **clist;
|
|
1030
|
|
1031 clist = cv->listdata;
|
|
1032 if (clist != NULL)
|
125
|
1033 fprintf (fd, "%s", clist[GPOINTER_TO_INT(cv->value)]);
|
122
|
1034 else
|
|
1035 fprintf (fd, _("<unknown>"));
|
|
1036
|
|
1037 return (0);
|
|
1038 }
|
|
1039
|
|
1040
|
125
|
1041 static int
|
|
1042 gftp_config_file_read_textcombo (char *str, gftp_config_vars * cv, int line)
|
|
1043 {
|
|
1044 char **clist;
|
|
1045 int i;
|
|
1046
|
|
1047 cv->value = NULL;
|
|
1048 if (cv->listdata != NULL)
|
|
1049 {
|
|
1050 clist = cv->listdata;
|
|
1051 for (i=0; clist[i] != NULL; i++)
|
|
1052 {
|
|
1053 if (strcasecmp (clist[i], str) == 0)
|
|
1054 {
|
|
1055 cv->value = clist[i];
|
|
1056 break;
|
|
1057 }
|
|
1058 }
|
|
1059 }
|
|
1060
|
|
1061 return (0);
|
|
1062 }
|
|
1063
|
|
1064
|
|
1065 /* Note, the index numbers of this array must match up to the numbers in
|
122
|
1066 gftp_option_type_enum in gftp.h */
|
|
1067 gftp_option_type_var gftp_option_types[] = {
|
136
|
1068 {gftp_config_file_read_text, gftp_config_file_write_text, NULL, NULL, NULL},
|
|
1069 {gftp_config_file_read_textcombo, gftp_config_file_write_text, NULL, NULL, NULL},
|
|
1070 {gftp_config_file_read_text, gftp_config_file_write_text, NULL, NULL, NULL},
|
|
1071 {gftp_config_file_read_text, gftp_config_file_write_hidetext, NULL, NULL, NULL},
|
|
1072 {gftp_config_file_read_int, gftp_config_file_write_int, NULL, NULL, NULL},
|
|
1073 {gftp_config_file_read_checkbox, gftp_config_file_write_int, NULL, NULL, NULL},
|
|
1074 {gftp_config_file_read_intcombo, gftp_config_file_write_intcombo, NULL, NULL, NULL},
|
|
1075 {gftp_config_file_read_float, gftp_config_file_write_float, NULL, NULL, NULL},
|
|
1076 {gftp_config_file_read_color, gftp_config_file_write_color, NULL, NULL, NULL},
|
|
1077 {NULL, NULL, NULL, NULL, NULL},
|
|
1078 {NULL, NULL, NULL, NULL, NULL}
|
122
|
1079 };
|
|
1080
|
|
1081
|
|
1082 void
|
|
1083 gftp_lookup_global_option (char * key, void *value)
|
|
1084 {
|
|
1085 gftp_config_list_vars * tmplistvar;
|
|
1086 gftp_config_vars * tmpconfigvar;
|
|
1087
|
|
1088 if (gftp_global_options_htable != NULL &&
|
|
1089 (tmpconfigvar = g_hash_table_lookup (gftp_global_options_htable,
|
|
1090 key)) != NULL)
|
124
|
1091 memcpy (value, &tmpconfigvar->value, sizeof (value));
|
122
|
1092 else if ((tmplistvar = g_hash_table_lookup (gftp_config_list_htable,
|
|
1093 key)) != NULL)
|
124
|
1094 *(gftp_config_list_vars **) value = tmplistvar;
|
122
|
1095 else
|
|
1096 {
|
|
1097 fprintf (stderr, _("FATAL gFTP Error: Config option '%s' not found in global hash table\n"), key);
|
|
1098 exit (1);
|
|
1099 }
|
|
1100 }
|
|
1101
|
|
1102
|
|
1103 void
|
|
1104 gftp_lookup_request_option (gftp_request * request, char * key, void *value)
|
|
1105 {
|
143
|
1106 gftp_config_vars * tmpconfigvar;
|
|
1107
|
|
1108 if (request != NULL && request->local_options_hash != NULL &&
|
|
1109 (tmpconfigvar = g_hash_table_lookup (request->local_options_hash,
|
|
1110 key)) != NULL)
|
|
1111 memcpy (value, &tmpconfigvar->value, sizeof (value));
|
|
1112 else
|
|
1113 gftp_lookup_global_option (key, value);
|
122
|
1114 }
|
|
1115
|
|
1116
|
|
1117 void
|
|
1118 gftp_set_global_option (char * key, void *value)
|
|
1119 {
|
129
|
1120 gftp_config_vars * tmpconfigvar;
|
|
1121
|
|
1122 if (gftp_global_options_htable != NULL &&
|
|
1123 (tmpconfigvar = g_hash_table_lookup (gftp_global_options_htable,
|
|
1124 key)) != NULL)
|
|
1125 memcpy (&tmpconfigvar->value, value, sizeof (tmpconfigvar->value));
|
|
1126 else
|
|
1127 {
|
|
1128 fprintf (stderr, _("FATAL gFTP Error: Config option '%s' not found in global hash table\n"), key);
|
|
1129 exit (1);
|
|
1130 }
|
122
|
1131 }
|
|
1132
|
|
1133
|
|
1134 void
|
|
1135 gftp_set_request_option (gftp_request * request, char * key, void *value)
|
|
1136 {
|
136
|
1137 gftp_config_vars * tmpconfigvar;
|
|
1138
|
|
1139 if (request->local_options_hash == NULL)
|
|
1140 request->local_options_hash = g_hash_table_new (string_hash_function,
|
|
1141 string_hash_compare);
|
|
1142
|
|
1143 if ((tmpconfigvar = g_hash_table_lookup (request->local_options_hash,
|
|
1144 key)) != NULL)
|
143
|
1145 memcpy (&tmpconfigvar->value, &value, sizeof (tmpconfigvar->value));
|
136
|
1146 else
|
|
1147 {
|
143
|
1148 if (gftp_global_options_htable == NULL ||
|
136
|
1149 (tmpconfigvar = g_hash_table_lookup (gftp_global_options_htable,
|
|
1150 key)) == NULL)
|
|
1151 {
|
|
1152 fprintf (stderr, _("FATAL gFTP Error: Config option '%s' not found in global hash table\n"), key);
|
|
1153 exit (1);
|
|
1154 }
|
|
1155
|
|
1156 request->num_local_options_vars++;
|
|
1157 request->local_options_vars = g_realloc (request->local_options_vars,
|
199
|
1158 sizeof (gftp_config_vars) * request->num_local_options_vars);
|
136
|
1159
|
143
|
1160 memcpy (&request->local_options_vars[request->num_local_options_vars - 1],
|
136
|
1161 tmpconfigvar, sizeof (*tmpconfigvar));
|
143
|
1162 memcpy (&request->local_options_vars[request->num_local_options_vars - 1].value, &value, sizeof (value));
|
|
1163
|
|
1164 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
|
1165 }
|
122
|
1166 }
|
|
1167
|
|
1168
|
|
1169 void
|
|
1170 gftp_register_config_vars (gftp_config_vars * config_vars)
|
|
1171 {
|
|
1172 gftp_options_list = g_list_append (gftp_options_list, config_vars);
|
|
1173 gftp_setup_global_options (config_vars);
|
|
1174 }
|
|
1175
|
199
|
1176
|
|
1177 void
|
|
1178 gftp_copy_local_options (gftp_config_vars ** new_options_vars,
|
|
1179 GHashTable ** new_options_hash,
|
|
1180 gftp_config_vars * orig_options,
|
|
1181 int num_local_options_vars)
|
|
1182 {
|
|
1183 int i;
|
|
1184
|
|
1185 if (orig_options == NULL || num_local_options_vars == 0)
|
|
1186 {
|
|
1187 *new_options_vars = NULL;
|
|
1188 *new_options_hash = NULL;
|
|
1189 return;
|
|
1190 }
|
|
1191
|
|
1192 *new_options_hash = g_hash_table_new (string_hash_function,
|
|
1193 string_hash_compare);
|
|
1194
|
|
1195 *new_options_vars = g_malloc (sizeof (gftp_config_vars) * num_local_options_vars);
|
|
1196 memcpy (*new_options_vars, orig_options,
|
|
1197 sizeof (gftp_config_vars) * num_local_options_vars);
|
|
1198
|
|
1199 for (i=0; i<num_local_options_vars; i++)
|
|
1200 {
|
|
1201 g_hash_table_insert (*new_options_hash, (*new_options_vars)[i].key,
|
|
1202 &(*new_options_vars)[i]);
|
|
1203
|
|
1204 /* FIXME - copy option values */
|
|
1205 }
|
|
1206 }
|
|
1207
|