33 |
|
|
34 |
#include "common.h" |
#include "common.h" |
35 |
#include "options.h" |
#include "options.h" |
36 |
|
#include "checkopt.h" |
37 |
#include "utils.h" |
#include "utils.h" |
38 |
#include "log.h" |
#include "log.h" |
39 |
|
|
60 |
/* GENERAL CONFIGURATION */ |
/* GENERAL CONFIGURATION */ |
61 |
STR(0, "access-method", "access_method", "modem", |
STR(0, "access-method", "access_method", "modem", |
62 |
"set the media used to access AOL.", "METHOD", |
"set the media used to access AOL.", "METHOD", |
63 |
__general, NULL), |
__general, check_access_method), |
64 |
|
|
65 |
STR(0, "protocol", "protocol", "p3", |
STR(0, "protocol", "protocol", "p3", |
66 |
"set the protocol used for communication with AOL.", "PROT", |
"set the protocol used for communication with AOL.", "PROT", |
67 |
__general, NULL), |
__general, check_protocol), |
68 |
|
|
69 |
STR('t', "interface-type", "interface_type", "tun", |
STR('t', "interface-type", "interface_type", "tun", |
70 |
"set the interface type.", "TYPE", |
"set the interface type.", "TYPE", |
71 |
__netiface, NULL), |
__netiface, check_iface_type), |
72 |
|
|
73 |
STR('i', "interface", "interface_name", NULL, |
STR('i', "interface", "interface_name", NULL, |
74 |
"set the interface name.", "NAME", |
"set the interface name.", "NAME", |
76 |
|
|
77 |
INT('u', "use-sn", "use_screen_name", 1, |
INT('u', "use-sn", "use_screen_name", 1, |
78 |
"use screen-name number NUM to connect.", "NUM", |
"use screen-name number NUM to connect.", "NUM", |
79 |
__auth, NULL), |
__auth, check_use_sn), |
80 |
|
|
81 |
STR(0, "screen-name", "screen_name1", NULL, |
STR(0, "screen-name", "screen_name1", NULL, |
82 |
"set the primary screen-name.", "SN", |
"set the primary screen-name.", "SN", |
140 |
|
|
141 |
INT(0, "reconnect-delay", "reconnect_delay", 0, |
INT(0, "reconnect-delay", "reconnect_delay", 0, |
142 |
"set the delay between reconnections.", "DELAY", |
"set the delay between reconnections.", "DELAY", |
143 |
__general, NULL), |
__general, check_natural), |
144 |
|
|
145 |
BOOL('d', "daemon", "daemon", false, |
BOOL('d', "daemon", "daemon", false, |
146 |
"enable daemon mode, run in background.", NULL, |
"enable daemon mode, run in background.", NULL, |
148 |
|
|
149 |
INT('D', "debug-level", "debug_level", -1, |
INT('D', "debug-level", "debug_level", -1, |
150 |
"set the verbosity level of the debug.", "LEVEL", |
"set the verbosity level of the debug.", "LEVEL", |
151 |
__general, NULL), |
__general, check_debug_level), |
152 |
|
|
153 |
BOOL(0, "dns", "set_dns", true, |
BOOL(0, "dns", "set_dns", true, |
154 |
"set the dns when connected.", NULL, |
"set the dns when connected.", NULL, |
247 |
|
|
248 |
INT('s', "line-speed", "line_speed", 115200, |
INT('s', "line-speed", "line_speed", 115200, |
249 |
"set the serial line speed.", "SPEED", |
"set the serial line speed.", "SPEED", |
250 |
__modem, NULL), |
__modem, check_line_speed), |
251 |
|
|
252 |
STR(0, NULL, "login_prompt", "ogin:", |
STR(0, NULL, "login_prompt", "ogin:", |
253 |
NULL, NULL, |
NULL, NULL, |
275 |
|
|
276 |
INT(0, NULL, "dial_retry", 3, |
INT(0, NULL, "dial_retry", 3, |
277 |
NULL, NULL, |
NULL, NULL, |
278 |
__modem, NULL), |
__modem, check_natural), |
279 |
|
|
280 |
INT(0, NULL, "retry_delay", 0, |
INT(0, NULL, "retry_delay", 0, |
281 |
NULL, NULL, |
NULL, NULL, |
282 |
__modem, NULL), |
__modem, check_natural), |
283 |
|
|
284 |
BOOL(0, NULL, "abort_busy", true, |
BOOL(0, NULL, "abort_busy", true, |
285 |
NULL, NULL, |
NULL, NULL, |
299 |
|
|
300 |
INT(0, NULL, "aol_port", 5190, |
INT(0, NULL, "aol_port", 5190, |
301 |
NULL, NULL, |
NULL, NULL, |
302 |
__cable, NULL), |
__cable, check_port), |
303 |
|
|
304 |
STR(0, NULL, "cable_iface", "eth0", |
STR(0, NULL, "cable_iface", "eth0", |
305 |
NULL, NULL, |
NULL, NULL, |
307 |
|
|
308 |
STR(0, NULL, "connect_ip", "0.0.0.0", |
STR(0, NULL, "connect_ip", "0.0.0.0", |
309 |
NULL, NULL, |
NULL, NULL, |
310 |
__cable, NULL) |
__cable, check_ip) |
311 |
#endif /* WITH_CABLE */ |
#endif /* WITH_CABLE */ |
312 |
}; |
}; |
313 |
|
|
448 |
#ifdef WITH_TUN |
#ifdef WITH_TUN |
449 |
printf("WITH_TUN "); |
printf("WITH_TUN "); |
450 |
#endif |
#endif |
451 |
|
printf("\n"); |
452 |
exit (0); |
exit (0); |
453 |
} |
} |
454 |
|
|
475 |
param[i].value.integer = atoi (optarg); |
param[i].value.integer = atoi (optarg); |
476 |
break; |
break; |
477 |
case string: |
case string: |
478 |
if (param[i].defined && (param[i].value.string != NULL)) |
if (param[i].allocated && (param[i].value.string != NULL)) |
479 |
free (param[i].value.string); |
free (param[i].value.string); |
480 |
param[i].value.string = strdup (optarg); |
param[i].value.string = strdup (optarg); |
481 |
} |
} |
482 |
|
param[i].defined = true; |
483 |
} |
} |
484 |
return 1; |
return 1; |
485 |
} |
} |
598 |
return 1; |
return 1; |
599 |
} |
} |
600 |
|
|
601 |
|
int |
602 |
|
check_config (void) |
603 |
|
{ |
604 |
|
int good = 1,i; |
605 |
|
|
606 |
|
debug(5, "Checking options:\n"); |
607 |
|
for (i = 0; i < PARAM_MAX; i++) |
608 |
|
switch(param[i].type) |
609 |
|
{ |
610 |
|
case boolean: |
611 |
|
if(param[i].defined) |
612 |
|
{ |
613 |
|
if(PARAM_BOOLEAN(i) == true) |
614 |
|
debug(5, " %s = true\n", param[i].name); |
615 |
|
else |
616 |
|
debug(5, " %s = false\n", param[i].name); |
617 |
|
} |
618 |
|
else |
619 |
|
debug(8, " %s = (default)\n", param[i].name); |
620 |
|
|
621 |
|
if(param[i].checkfn.check_boolean != NULL) |
622 |
|
good &= param[i].checkfn.check_boolean (param[i].name, |
623 |
|
PARAM_BOOLEAN(i)); |
624 |
|
break; |
625 |
|
case integer: |
626 |
|
if(param[i].defined) |
627 |
|
debug(5, " %s = %d\n", param[i].name, PARAM_INTEGER(i)); |
628 |
|
else |
629 |
|
debug(8, " %s = (default)\n", param[i].name); |
630 |
|
|
631 |
|
if(param[i].checkfn.check_integer != NULL) |
632 |
|
good &= param[i].checkfn.check_integer (param[i].name, |
633 |
|
PARAM_INTEGER(i)); |
634 |
|
break; |
635 |
|
case string: |
636 |
|
if(param[i].defined) |
637 |
|
{ |
638 |
|
if(PARAM_STRING(i) != NULL) |
639 |
|
{ |
640 |
|
if(i>__password7 || i<__screen_name1) |
641 |
|
debug(5, " %s = %s\n", param[i].name, PARAM_STRING(i)); |
642 |
|
else |
643 |
|
debug(5, " %s = (hidden)\n", param[i].name); |
644 |
|
} |
645 |
|
else |
646 |
|
debug(5, " %s = (undefined)\n", param[i].name); |
647 |
|
} |
648 |
|
else |
649 |
|
debug(8, " %s = (default)\n", param[i].name); |
650 |
|
if(param[i].checkfn.check_string != NULL) |
651 |
|
good &= param[i].checkfn.check_string (param[i].name, |
652 |
|
PARAM_STRING(i)); |
653 |
|
break; |
654 |
|
} |
655 |
|
debug(5,"\n"); |
656 |
|
|
657 |
|
return good; |
658 |
|
} |
659 |
|
|
660 |
/* |
/* |
661 |
* Config file |
* Config file |
662 |
*/ |
*/ |
|
|
|
663 |
int |
int |
664 |
parse_config () |
parse_config () |
665 |
{ |
{ |
670 |
snprintf (homeconfig, 249, "%s/.%s", home, HOME_CONFIG); |
snprintf (homeconfig, 249, "%s/.%s", home, HOME_CONFIG); |
671 |
|
|
672 |
if (!parse_config_file (DEFAULT_CONFIG)) |
if (!parse_config_file (DEFAULT_CONFIG)) |
673 |
debug (1,"No global config found.\n"); |
debug (5,"No global config found.\n"); |
674 |
if (!parse_config_file (homeconfig)) |
if (!parse_config_file (homeconfig)) |
675 |
debug (1,"No personnal config found.\n"); |
debug (5,"No personnal config found.\n"); |
676 |
|
|
677 |
debug (1,"\n"); |
debug (1,"\n"); |
678 |
return 1; |
return 1; |
684 |
{ |
{ |
685 |
FILE *f; |
FILE *f; |
686 |
char line[256]; |
char line[256]; |
687 |
int i, lineno = 0; |
int i, found, lineno = 0; |
688 |
char *name, *value; |
char *name, *value; |
689 |
|
|
690 |
f = fopen (filename, "r"); |
f = fopen (filename, "r"); |
691 |
if (f == NULL) |
if (f == NULL) |
692 |
{ |
{ |
693 |
debug (2,"%s: %s(%d)\n",filename, strerror(errno), errno); |
debug (6,"%s: %s(%d)\n",filename, strerror(errno), errno); |
694 |
return 0; |
return 0; |
695 |
} |
} |
696 |
while (!feof (f)) |
while (!feof (f)) |
700 |
break; |
break; |
701 |
strip_comments (line); |
strip_comments (line); |
702 |
trim (line); |
trim (line); |
703 |
if (strlen (line) > 0 && tokenize_line (line, &name, &value)) |
if (strlen (line) > 0 && !tokenize_line (line, &name, &value)) |
704 |
log (LOG_WARNING, "%s:%d Bad line format\n", filename, lineno); |
log (LOG_WARNING, "%s:%d bad line format\n", filename, lineno); |
705 |
else |
else |
706 |
{ |
{ |
707 |
for (i = 0; i < PARAM_MAX; i++) |
if (strlen (line) > 0) { |
708 |
{ |
for (i = 0, found = 0; i < PARAM_MAX && !found; i++) |
709 |
if (strlen (line) > 0) |
found=try_param (¶m[i], filename, lineno, name, value); |
710 |
try_param (¶m[i], filename, lineno, name, value); |
if(!found) |
711 |
} |
log (LOG_WARNING, "%s:%d unrecognized option - %s\n", |
712 |
|
filename, lineno, name); |
713 |
|
} |
714 |
} |
} |
715 |
} |
} |
716 |
return 1; |
return 1; |
717 |
} |
} |
718 |
|
|
719 |
void |
int |
720 |
try_param (param, filename, lineno, name, value) |
try_param (param, filename, lineno, name, value) |
721 |
param_t *param; |
param_t *param; |
722 |
char *filename; |
char *filename; |
732 |
if (get_boolean (¶m->value.boolean, value)) |
if (get_boolean (¶m->value.boolean, value)) |
733 |
param->defined = true; |
param->defined = true; |
734 |
else |
else |
735 |
log (LOG_WARNING, "%s:%d Bad boolean value\n", filename, lineno); |
log (LOG_WARNING, "%s:%d bad boolean value\n", filename, lineno); |
736 |
break; |
break; |
737 |
case string: |
case string: |
738 |
if (get_string (¶m->value.string, value)) |
if (get_string (¶m->value.string, value)) |
739 |
param->defined = true; |
{ |
740 |
|
param->defined = true; |
741 |
|
param->allocated = true; |
742 |
|
} |
743 |
else |
else |
744 |
{ |
{ |
745 |
log (LOG_CRIT, "%s:%d Not enough memory to get the parameter\n", |
log (LOG_CRIT, "%s:%d not enough memory to get the parameter\n", |
746 |
filename, lineno); |
filename, lineno); |
747 |
exit(1); |
exit(1); |
748 |
} |
} |
751 |
if (get_integer (¶m->value.integer, value)) |
if (get_integer (¶m->value.integer, value)) |
752 |
param->defined = true; |
param->defined = true; |
753 |
else |
else |
754 |
log (LOG_WARNING, "%s:%d Bad integer value\n", filename, lineno); |
log (LOG_WARNING, "%s:%d bad integer value\n", filename, lineno); |
755 |
break; |
break; |
756 |
} |
} |
757 |
|
return 1; |
758 |
} |
} |
759 |
|
else |
760 |
|
return 0; |
761 |
} |
} |
762 |
|
|
763 |
int |
int |
831 |
|
|
832 |
delim = strchr (line, '='); |
delim = strchr (line, '='); |
833 |
if (delim == NULL) |
if (delim == NULL) |
834 |
return 1; |
return 0; |
835 |
*delim = '\0'; |
*delim = '\0'; |
836 |
*name = line; |
*name = line; |
837 |
*value = delim + 1; |
*value = delim + 1; |
838 |
trim (*name); |
trim (*name); |
839 |
trim (*value); |
trim (*value); |
840 |
return 0; |
return 1; |
841 |
} |
} |