--- chan_dahdi.c.2 2009-08-09 21:20:51.000000000 +1200 +++ chan_dahdi.c 2009-08-11 00:13:05.000000000 +1200 @@ -1664,7 +1664,8 @@ static int my_distinctive_ring(struct as * distinctive ringing */ if ((checkaftercid && distinctiveringaftercid) || !checkaftercid) { /* Clear the current ring data array so we dont have old data in it. */ - for (receivedRingT = 0; receivedRingT < ARRAY_LEN(ringdata); receivedRingT++) +// for (receivedRingT = 0; receivedRingT < ARRAY_LEN(ringdata); receivedRingT++) + for (receivedRingT = 0; receivedRingT < 3; receivedRingT++) ringdata[receivedRingT] = 0; receivedRingT = 0; if (checkaftercid && distinctiveringaftercid) @@ -1690,12 +1691,18 @@ static int my_distinctive_ring(struct as ringdata[receivedRingT] = analog_p->ringt; - if (analog_p->ringt < analog_p->ringt_base/2) - break; /* Increment the ringT counter so we can match it against values in chan_dahdi.conf for distinctive ring */ - if (++receivedRingT == ARRAY_LEN(ringdata)) + +// if (++receivedRingT == ARRAY_LEN(ringdata)) { + if (++receivedRingT == 3) { + ast_verb(3, "Detected ring pattern: %d,%d,%d\n", ringdata[0], ringdata[1], ringdata[2]); + break; + } + if (analog_p->ringt < analog_p->ringt_base/2) { + ast_verb(3, "Detected ring pattern: %d,%d,%d\n", ringdata[0], ringdata[1], ringdata[2]); break; + } } else if (i & DAHDI_IOMUX_READ) { res = read(p->subs[idx].dfd, buf, sizeof(buf)); if (res < 0) { @@ -1704,15 +1711,18 @@ static int my_distinctive_ring(struct as ast_hangup(chan); return 1; } + ast_verb(3, "Detected ring pattern: %d,%d,%d\n", ringdata[0], ringdata[1], ringdata[2]); break; } if (analog_p->ringt) analog_p->ringt--; if (analog_p->ringt == 1) { res = -1; + ast_verb(3, "Detected ring pattern: %d,%d,%d\n", ringdata[0], ringdata[1], ringdata[2]); break; } } + } } if ((checkaftercid && usedistinctiveringdetection) || !checkaftercid) { @@ -1743,9 +1753,17 @@ static int my_distinctive_ring(struct as if (distMatches == 3) { /* The ring matches, set the context to whatever is for distinctive ring.. */ - ast_copy_string(p->context, p->drings.ringContext[counter].contextData, sizeof(p->context)); - ast_copy_string(chan->context, p->drings.ringContext[counter].contextData, sizeof(chan->context)); - ast_verb(3, "Distinctive Ring matched context %s\n",p->context); + if (!ast_strlen_zero(p->drings.ringContext[counter].contextData)) { + ast_copy_string(p->context, p->drings.ringContext[counter].contextData, sizeof(p->context)); + ast_copy_string(chan->context, p->drings.ringContext[counter].contextData, sizeof(chan->context)); + ast_verb(3, "Distinctive Ring matched context %s\n", p->context); + } else { + ast_log(LOG_WARNING, "Distinctive Ring matched: 'dring%dcontext' not defined???\n", counter+1); + if (strcmp(p->context,p->defcontext) != 0) { + ast_copy_string(p->context, p->defcontext, sizeof(p->context)); + ast_copy_string(chan->context,p->defcontext,sizeof(chan->context)); + } + } break; } }