Refactoring validity check and prefix processing of dialed number
Command line help shows how many digits and what prefixes can be dialed. Giving a station ID via command line will be checked for being valid. The number to call the mobile statione will be checked for being valid. Prefixes that are defined for a nework will be removed from station ID automatically. Multiple station ID lengths are supported: * C-Netz: 7 or 8 digits, depending on area code length * A-Netz: 5 or 7 digits; number is truncated to last 5 digits. * IMTS/MTS: 5 or 7 digits, depending on phone's selector switch.
This commit is contained in:
@@ -660,35 +660,7 @@ int call_down_setup(int callref, const char __attribute__((unused)) *caller_id,
|
||||
sender_t *sender;
|
||||
euro_t *euro;
|
||||
euro_call_t *call;
|
||||
int i;
|
||||
|
||||
/* check prefix to choose correct channel */
|
||||
if (strlen(dialing) == 10) {
|
||||
if (!strncmp(dialing, "0279", 4)) {
|
||||
dialing += 4;
|
||||
channel = 'A';
|
||||
}
|
||||
if (!strncmp(dialing, "0509", 4)) {
|
||||
dialing += 4;
|
||||
channel = 'B';
|
||||
}
|
||||
if (!strncmp(dialing, "0709", 4)) {
|
||||
dialing += 4;
|
||||
channel = 'B';
|
||||
}
|
||||
}
|
||||
/* number invalid */
|
||||
if (strlen(dialing) != 6) {
|
||||
inval:
|
||||
PDEBUG(DEURO, DEBUG_NOTICE, "Call to invalid ID '%s', rejecting!\n", dialing);
|
||||
return -CAUSE_INVALNUMBER;
|
||||
}
|
||||
for (i = 0; i < 6; i++) {
|
||||
if (!(dialing[i] >= '0' && dialing[i] <= '9')
|
||||
&& !(dialing[i] >= 'a' && dialing[i] <= 'e')
|
||||
&& !(dialing[i] >= 'A' && dialing[i] <= 'E'))
|
||||
goto inval;
|
||||
}
|
||||
|
||||
/* find transmitter */
|
||||
for (sender = sender_head; sender; sender = sender->next) {
|
||||
|
||||
@@ -81,8 +81,7 @@ void print_help(const char *arg0)
|
||||
printf(" to page a recevier.\n");
|
||||
printf(" --repeat <num>\n");
|
||||
printf(" Repead paging ID <num> times when transmitting. (default = %d)\n", repeat);
|
||||
printf("\nstation-id: Give 6 digit station-id, you don't need to enter it for every\n");
|
||||
printf(" start of this program.\n");
|
||||
main_mobile_print_station_id();
|
||||
main_mobile_print_hotkeys();
|
||||
}
|
||||
|
||||
@@ -102,25 +101,6 @@ static void add_options(void)
|
||||
option_add(OPT_REPEAT, "repeat", 1);
|
||||
}
|
||||
|
||||
static int check_id(const char *id)
|
||||
{
|
||||
int i;
|
||||
|
||||
if (strlen(id) != 6) {
|
||||
fprintf(stderr, "Given paging ID must have exactly 6 digits!\n");
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
for (i = 0; i < 6; i++) {
|
||||
if (id[i] < '0' || id[i] > '9') {
|
||||
fprintf(stderr, "Given paging ID must have digits (0..9) only!\n");
|
||||
return -EINVAL;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int handle_options(int short_option, int argi, char **argv)
|
||||
{
|
||||
switch (short_option) {
|
||||
@@ -134,20 +114,20 @@ static int handle_options(int short_option, int argi, char **argv)
|
||||
rx = 1;
|
||||
break;
|
||||
case 'I':
|
||||
if (check_id(argv[argi]))
|
||||
if (main_mobile_number_ask(argv[argi], "ID (--id)"))
|
||||
return -EINVAL;
|
||||
euro_add_id(argv[argi]);
|
||||
euro_add_id(mobile_number_remove_prefix(argv[argi]));
|
||||
break;
|
||||
case 'D':
|
||||
degraded = 1;
|
||||
break;
|
||||
case 'S':
|
||||
if (check_id(argv[argi]))
|
||||
if (main_mobile_number_ask(argv[argi], "ID to scan from"))
|
||||
return -EINVAL;
|
||||
scan_from = atoi(argv[argi++]);
|
||||
if (check_id(argv[argi]))
|
||||
scan_from = atoi(mobile_number_remove_prefix((argv[argi++])));
|
||||
if (main_mobile_number_ask(argv[argi], "ID to scan to"))
|
||||
return -EINVAL;
|
||||
scan_to = atoi(argv[argi++]) + 1;
|
||||
scan_to = atoi(mobile_number_remove_prefix(argv[argi++])) + 1;
|
||||
break;
|
||||
case OPT_RANDOM:
|
||||
random_id = 1;
|
||||
@@ -162,6 +142,21 @@ static int handle_options(int short_option, int argi, char **argv)
|
||||
return 1;
|
||||
}
|
||||
|
||||
static const struct number_lengths number_lengths[] = {
|
||||
{ 6, "number" },
|
||||
{ 0, NULL }
|
||||
};
|
||||
|
||||
static const char *number_prefixes[] = {
|
||||
"0279xxxxxx",
|
||||
"+49279xxxxxx",
|
||||
"0509xxxxxx",
|
||||
"+49509xxxxxx",
|
||||
"0709xxxxxx",
|
||||
"+49709xxxxxx",
|
||||
NULL
|
||||
};
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int rc, argi;
|
||||
@@ -178,8 +173,7 @@ int main(int argc, char *argv[])
|
||||
init_es_kaudn();
|
||||
|
||||
/* init mobile interface */
|
||||
console_digits = "0123456789ABCDE";
|
||||
main_mobile_init();
|
||||
main_mobile_init("0123456789ABCDEabcde", number_lengths, number_prefixes, NULL);
|
||||
|
||||
/* handle options / config file */
|
||||
add_options();
|
||||
@@ -192,10 +186,9 @@ int main(int argc, char *argv[])
|
||||
|
||||
if (argi < argc) {
|
||||
station_id = argv[argi];
|
||||
if (strlen(station_id) != 6) {
|
||||
printf("Given receiver ID '%s' does not have 6 digits\n", station_id);
|
||||
return 0;
|
||||
}
|
||||
rc = main_mobile_number_ask(station_id, "station ID");
|
||||
if (rc)
|
||||
return rc;
|
||||
}
|
||||
|
||||
if (!num_kanal) {
|
||||
@@ -239,7 +232,7 @@ int main(int argc, char *argv[])
|
||||
printf("Base station for channel %s ready, please tune transmitter and/or receiver to %.4f MHz\n", kanal[i], euro_kanal2freq(kanal[i], fm) / 1e6);
|
||||
}
|
||||
|
||||
main_mobile("eurosignal", &quit, NULL, station_id, 6);
|
||||
main_mobile_loop("eurosignal", &quit, NULL, station_id);
|
||||
|
||||
fail:
|
||||
/* destroy transceiver instance */
|
||||
|
||||
Reference in New Issue
Block a user