|
|
|
@ -159,6 +159,112 @@ static const char *timer_ident_name(enum timer_ident ident)
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* dial hints
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
static struct dial_hint *dial_hints = NULL;
|
|
|
|
|
|
|
|
|
|
int add_dial_hint(const char *arg)
|
|
|
|
|
{
|
|
|
|
|
struct dial_hint *hint;
|
|
|
|
|
int i, dash;
|
|
|
|
|
|
|
|
|
|
hint = calloc(1, sizeof(*hint));
|
|
|
|
|
if (!hint)
|
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
|
|
for (i = 0, dash = -1; arg[i]; i++) {
|
|
|
|
|
if (arg[i] == '-') {
|
|
|
|
|
/* only single dash is allowed */
|
|
|
|
|
if (dash >= 0)
|
|
|
|
|
goto error;
|
|
|
|
|
dash = i;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
/* only digits 0..9 are allowd */
|
|
|
|
|
if (arg[i] < '0' || arg[i] > '9')
|
|
|
|
|
goto error;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (dash < 0) {
|
|
|
|
|
/* number must have at least one digit */
|
|
|
|
|
if (i < 1)
|
|
|
|
|
goto error;
|
|
|
|
|
hint->length = i;
|
|
|
|
|
hint->from = calloc(1, i + 1);
|
|
|
|
|
if (!hint->from)
|
|
|
|
|
goto error;
|
|
|
|
|
strcpy(hint->from, arg);
|
|
|
|
|
PDEBUG(DTEL, DEBUG_INFO, "Added dial hint '%s'\n", hint->from);
|
|
|
|
|
} else {
|
|
|
|
|
/* both numbers must have same lenth */
|
|
|
|
|
if (dash != i - dash - 1)
|
|
|
|
|
goto error;
|
|
|
|
|
/* there must be digits at all */
|
|
|
|
|
if (dash < 1)
|
|
|
|
|
goto error;
|
|
|
|
|
hint->length = dash;
|
|
|
|
|
hint->from = calloc(1, dash + 1);
|
|
|
|
|
if (!hint->from)
|
|
|
|
|
goto error;
|
|
|
|
|
strncpy(hint->from, arg, dash);
|
|
|
|
|
hint->to = calloc(1, dash + 1);
|
|
|
|
|
if (!hint->to)
|
|
|
|
|
goto error;
|
|
|
|
|
strcpy(hint->to, arg + dash + 1);
|
|
|
|
|
/* second string must be greater than first string */
|
|
|
|
|
if (strcmp(hint->from, hint->to) > 0)
|
|
|
|
|
goto error;
|
|
|
|
|
PDEBUG(DTEL, DEBUG_INFO, "Added dial hint '%s' - '%s'\n", hint->from, hint->to);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hint->next = dial_hints;
|
|
|
|
|
dial_hints = hint;
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
error:
|
|
|
|
|
free(hint->from);
|
|
|
|
|
free(hint->to);
|
|
|
|
|
free(hint);
|
|
|
|
|
|
|
|
|
|
return -EINVAL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int check_dial_hint(const char *number)
|
|
|
|
|
{
|
|
|
|
|
struct dial_hint *hint;
|
|
|
|
|
size_t length = strlen(number);
|
|
|
|
|
|
|
|
|
|
for (hint = dial_hints; hint; hint = hint->next) {
|
|
|
|
|
if (hint->length != length)
|
|
|
|
|
continue;
|
|
|
|
|
if (hint->from && !hint->to) {
|
|
|
|
|
if (strncmp(number, hint->from, hint->length) == 0)
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
if (hint->from && hint->to) {
|
|
|
|
|
if (strncmp(number, hint->from, hint->length) >= 0
|
|
|
|
|
&& strncmp(number, hint->to, hint->length) <= 0)
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void purge_dial_hints(void)
|
|
|
|
|
{
|
|
|
|
|
struct dial_hint *hint;
|
|
|
|
|
|
|
|
|
|
while ((hint = dial_hints)) {
|
|
|
|
|
dial_hints = hint->next;
|
|
|
|
|
free(hint->from);
|
|
|
|
|
free(hint->to);
|
|
|
|
|
free(hint);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Endpoint instance
|
|
|
|
|
*/
|
|
|
|
@ -521,7 +627,7 @@ void recv_dtmf(void *priv, char digit, dtmf_meas_t __attribute__((unused)) *meas
|
|
|
|
|
/* if we are receiving digits en block */
|
|
|
|
|
if (pstn->call[PSTN_CALL_ACTIVE]->state == CALL_STATE_ENBLOCK) {
|
|
|
|
|
if (digit == '#') {
|
|
|
|
|
PDEBUG(DTEL, DEBUG_DEBUG, "Number is complete, send setup\n");
|
|
|
|
|
PDEBUG(DTEL, DEBUG_DEBUG, "Digit '#' received, number is complete, send setup\n");
|
|
|
|
|
/* setup (en block) */
|
|
|
|
|
setup_ind(pstn, PSTN_CALL_ACTIVE, pstn->dialing, 1);
|
|
|
|
|
return;
|
|
|
|
@ -531,6 +637,12 @@ void recv_dtmf(void *priv, char digit, dtmf_meas_t __attribute__((unused)) *meas
|
|
|
|
|
char called[2] = { digit, '\0' };
|
|
|
|
|
strncat(pstn->dialing, called, sizeof(pstn->dialing) - 1);
|
|
|
|
|
PDEBUG(DTEL, DEBUG_DEBUG, "Appending digit, so dial string is now: '%s'.\n", pstn->dialing);
|
|
|
|
|
if (check_dial_hint(pstn->dialing)) {
|
|
|
|
|
PDEBUG(DTEL, DEBUG_DEBUG, "Number in list of dial hints received, number is complete, send setup\n");
|
|
|
|
|
/* setup (en block) */
|
|
|
|
|
setup_ind(pstn, PSTN_CALL_ACTIVE, pstn->dialing, 1);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
/* start dial timer */
|
|
|
|
|
timer_on(pstn, (double)pstn->enblock, TIMER_IDENT_DIALING);
|
|
|
|
|
return;
|
|
|
|
@ -1492,6 +1604,12 @@ static void v5_sig_ind(pstn_t *pstn, uint8_t *data, int len)
|
|
|
|
|
/* append digit */
|
|
|
|
|
strncat(pstn->dialing, called, sizeof(pstn->dialing) - 1);
|
|
|
|
|
PDEBUG(DTEL, DEBUG_DEBUG, "Appending digit, so dial string is now: '%s'.\n", pstn->dialing);
|
|
|
|
|
if (check_dial_hint(pstn->dialing)) {
|
|
|
|
|
PDEBUG(DTEL, DEBUG_DEBUG, "Number in list of dial hints received, number is complete, send setup\n");
|
|
|
|
|
/* setup (en block) */
|
|
|
|
|
setup_ind(pstn, PSTN_CALL_ACTIVE, pstn->dialing, 1);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
/* start dial timer */
|
|
|
|
|
timer_on(pstn, (double)pstn->enblock, TIMER_IDENT_DIALING);
|
|
|
|
|
break;
|
|
|
|
|