Index: channels/chan_dahdi.c =================================================================== --- channels/chan_dahdi.c (revision 279272) +++ channels/chan_dahdi.c (working copy) @@ -1742,15 +1742,15 @@ * distinctive ringing */ if ((checkaftercid && distinctiveringaftercid) || !checkaftercid) { /* Clear the current ring data array so we don't have old data in it. */ - for (receivedRingT = 0; receivedRingT < RING_PATTERNS; receivedRingT++) + for (receivedRingT = 0; receivedRingT < RING_PATTERNS; receivedRingT++) { ringdata[receivedRingT] = 0; + } receivedRingT = 0; - if (checkaftercid && distinctiveringaftercid) + if (checkaftercid && distinctiveringaftercid) { ast_verb(3, "Detecting post-CID distinctive ring\n"); - /* Check to see if context is what it should be, if not set to be. */ - else if (strcmp(p->context,p->defcontext) != 0) { + } else if (strcmp(p->context, p->defcontext) != 0) { /* Check to see if context is what it should be, if not set to be. */ ast_copy_string(p->context, p->defcontext, sizeof(p->context)); - ast_copy_string(chan->context,p->defcontext,sizeof(chan->context)); + ast_copy_string(chan->context, p->defcontext, sizeof(chan->context)); } for (;;) { @@ -1769,15 +1769,16 @@ ast_log(LOG_NOTICE, "Got event %d (%s)...\n", res, event2str(res)); res = 0; /* Let us detect distinctive ring */ - ringdata[receivedRingT] = analog_p->ringt; - if (analog_p->ringt < analog_p->ringt_base/2) + 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 == RING_PATTERNS) + if (++receivedRingT == RING_PATTERNS) { break; + } } else if (i & DAHDI_IOMUX_READ) { res = read(p->subs[idx].dfd, buf, sizeof(buf)); if (res < 0) { @@ -1799,7 +1800,7 @@ } if ((checkaftercid && usedistinctiveringdetection) || !checkaftercid) { /* this only shows up if you have n of the dring patterns filled in */ - ast_verb(3, "Detected ring pattern: %d,%d,%d\n",ringdata[0],ringdata[1],ringdata[2]); + ast_verb(3, "Detected ring pattern: %d,%d,%d\n", ringdata[0], ringdata[1], ringdata[2]); for (counter = 0; counter < 3; counter++) { /* Check to see if the rings we received match any of the ones in chan_dahdi.conf for this channel */ distMatches = 0; @@ -1825,9 +1826,9 @@ 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); + ast_copy_string(p->context, S_OR(p->drings.ringContext[counter].contextData, p->defcontext), sizeof(p->context)); + ast_copy_string(chan->context, S_OR(p->drings.ringContext[counter].contextData, p->defcontext), sizeof(chan->context)); + ast_verb(3, "Distinctive Ring matched context %s\n", p->context); break; } } @@ -10187,7 +10188,7 @@ } } /* this only shows up if you have n of the dring patterns filled in */ - ast_verb(3, "Detected ring pattern: %d,%d,%d\n",curRingData[0],curRingData[1],curRingData[2]); + ast_verb(3, "Detected ring pattern: %d,%d,%d\n", curRingData[0], curRingData[1], curRingData[2]); for (counter = 0; counter < 3; counter++) { /* Check to see if the rings we received match any of the ones in chan_dahdi.conf for this channel */ @@ -10209,9 +10210,9 @@ 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); + ast_copy_string(p->context, S_OR(p->drings.ringContext[counter].contextData, p->defcontext), sizeof(p->context)); + ast_copy_string(chan->context, S_OR(p->drings.ringContext[counter].contextData, p->defcontext), sizeof(chan->context)); + ast_verb(3, "Distinctive Ring matched context %s\n", p->context); break; } } @@ -10221,8 +10222,9 @@ #if 1 restore_gains(p); #endif - } else + } else { ast_log(LOG_WARNING, "Unable to get caller ID space\n"); + } } else { ast_log(LOG_WARNING, "Channel %s in prering " "state, but I have nothing to do. " @@ -10419,7 +10421,7 @@ } if (p->usedistinctiveringdetection) { /* this only shows up if you have n of the dring patterns filled in */ - ast_verb(3, "Detected ring pattern: %d,%d,%d\n",curRingData[0],curRingData[1],curRingData[2]); + ast_verb(3, "Detected ring pattern: %d,%d,%d\n", curRingData[0], curRingData[1], curRingData[2]); for (counter = 0; counter < 3; counter++) { /* Check to see if the rings we received match any of the ones in chan_dahdi.conf for this @@ -10434,22 +10436,22 @@ ast_verb(3, "Ring pattern check range: %d\n", p->drings.ringnum[counter].range); if (p->drings.ringnum[counter].ring[counter1] == -1) { ast_verb(3, "Pattern ignore (-1) detected, so matching pattern %d regardless.\n", - curRingData[counter1]); + curRingData[counter1]); distMatches++; } else if (curRingData[counter1] <= (p->drings.ringnum[counter].ring[counter1] + p->drings.ringnum[counter].range) && curRingData[counter1] >= (p->drings.ringnum[counter].ring[counter1] - p->drings.ringnum[counter].range)) { ast_verb(3, "Ring pattern matched in range: %d to %d\n", - (p->drings.ringnum[counter].ring[counter1] - p->drings.ringnum[counter].range), - (p->drings.ringnum[counter].ring[counter1] + p->drings.ringnum[counter].range)); + (p->drings.ringnum[counter].ring[counter1] - p->drings.ringnum[counter].range), + (p->drings.ringnum[counter].ring[counter1] + p->drings.ringnum[counter].range)); distMatches++; } } 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); + ast_copy_string(p->context, S_OR(p->drings.ringContext[counter].contextData, p->defcontext), sizeof(p->context)); + ast_copy_string(chan->context, S_OR(p->drings.ringContext[counter].contextData, p->defcontext), sizeof(chan->context)); + ast_verb(3, "Distinctive Ring matched context %s\n", p->context); break; } } @@ -10462,11 +10464,13 @@ if (res < 0) { ast_log(LOG_WARNING, "CallerID returned with error on channel '%s'\n", chan->name); } - } else + } else { ast_log(LOG_WARNING, "Unable to get caller ID space\n"); + } } - } else + } else { cs = NULL; + } if (number) ast_shrink_phone_number(number); @@ -16261,11 +16265,11 @@ } else if (!strcasecmp(v->name, "distinctiveringaftercid")) { distinctiveringaftercid = ast_true(v->value); } else if (!strcasecmp(v->name, "dring1context")) { - ast_copy_string(confp->chan.drings.ringContext[0].contextData,v->value,sizeof(confp->chan.drings.ringContext[0].contextData)); + ast_copy_string(confp->chan.drings.ringContext[0].contextData, v->value, sizeof(confp->chan.drings.ringContext[0].contextData)); } else if (!strcasecmp(v->name, "dring2context")) { - ast_copy_string(confp->chan.drings.ringContext[1].contextData,v->value,sizeof(confp->chan.drings.ringContext[1].contextData)); + ast_copy_string(confp->chan.drings.ringContext[1].contextData, v->value, sizeof(confp->chan.drings.ringContext[1].contextData)); } else if (!strcasecmp(v->name, "dring3context")) { - ast_copy_string(confp->chan.drings.ringContext[2].contextData,v->value,sizeof(confp->chan.drings.ringContext[2].contextData)); + ast_copy_string(confp->chan.drings.ringContext[2].contextData, v->value, sizeof(confp->chan.drings.ringContext[2].contextData)); } else if (!strcasecmp(v->name, "dring1range")) { confp->chan.drings.ringnum[0].range = atoi(v->value); } else if (!strcasecmp(v->name, "dring2range")) {