3 * Copyright (C) 2010 Tomas 'ZeXx86' Jedrzejek (zexx86@zexos.org)
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 3 of the License, or
8 * (at your option) any later version.
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.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
26 config_t config
; /* structure with config values */
28 int config_parse (char *var
, char *val
)
30 if (!strcasecmp (var
, CONFIG_VAR_NAME
)) {
31 config
.name
= strdup (val
);
35 if (!strcasecmp (var
, CONFIG_VAR_PWD
)) {
36 config
.pwd
= strdup (val
);
40 if (!strcasecmp (var
, CONFIG_VAR_SERVER
)) {
41 config
.server
= strdup (val
);
45 if (!strcasecmp (var
, CONFIG_VAR_PORT
)) {
46 config
.port
= (unsigned short) atoi (strdup (val
));
53 /* load config file */
54 int config_load (char *filename
)
61 /* open specified file */
62 FILE *fp
= fopen (filename
, "r");
65 printf ("> WARNING -> config file '%s' not found\n", DEFAULT_CONFIG_PATH
);
69 buffer
= (char *) calloc (600, sizeof (char));
76 char *r
= fgets (buffer
, 600, fp
);
88 if (buffer
[l
- 1] == '\n')
89 buffer
[l
-- - 1] = '\0';
91 /* move to first valid letter */
92 for (c
= buffer
; *c
&& *c
== ' '; c
++);
99 sscanf (c
, "%s %s", var
, val
);
101 config_parse (var
, val
);
104 memset (buffer
, 0, l
);
115 memset (&config
, 0, sizeof (config_t
));
117 int ret
= config_load (DEFAULT_CONFIG_PATH
);
119 if (!ret
&& (!config
.name
|| !config
.pwd
|| !config
.server
)) {
120 printf ("ERROR -> config file is not valid !\nPlease rewrite " DEFAULT_CONFIG_PATH
" in this way:\n\n"
122 "\tpassword YOURPASSWORD\n"
123 "\tserver TUNNELSERVER\n"