Index: chan_zap.c =================================================================== RCS file: /usr/cvsroot/asterisk/channels/chan_zap.c,v retrieving revision 1.303 diff -c -r1.303 chan_zap.c *** chan_zap.c 19 Jul 2004 16:00:40 -0000 1.303 --- chan_zap.c 21 Jul 2004 23:44:55 -0000 *************** *** 795,800 **** --- 795,808 ---- return 0; } + static int zt_get_history(int fd, void *buf, int buf_size) + { + struct zt_history hist; + hist.buf=buf; + hist.len=buf_size; + return ioctl(fd, ZT_GET_HISTORY, &hist); + } + static int alloc_sub(struct zt_pvt *p, int x) { ZT_BUFFERINFO bi; *************** *** 5016,5024 **** } } #endif ! if (p->use_callerid) { ! cs = callerid_new(); ! if (cs) { #if 1 bump_gains(p); #endif --- 5024,5062 ---- } } #endif ! if(p->use_callerid == 2) { /* UK callerid is before the ring, so we already have the data */ ! ast_log(LOG_DEBUG,"Using UK-style caller ID\n"); ! cs = callerid_new(); ! if (cs) { ! unsigned char cidbuf[16384]; ! res=0; ! ! /* UK caller ID is V23 not Bell202 */ ! callerid_set_v23(cs); ! res = zt_get_history(p->subs[index].zfd,cidbuf,sizeof(cidbuf)); ! if(res<0) { ! ast_log(LOG_ERROR,"zt_get_history failed: %s\n", strerror(errno)); ! } else { ! res=callerid_feed(cs,cidbuf,sizeof(cidbuf),AST_LAW(p)); ! if (res < 0) { ! ast_log(LOG_WARNING, "CallerID feed failed: %s\n", strerror(errno)); ! } ! } ! ! if(res==1) { ! callerid_get(cs, &name, &number, &flags); ! if (option_debug) ! ast_log(LOG_DEBUG, "CallerID number: %s, name: %s, flags=%d\n", number, name, flags); ! } ! } ! } ! if (usedistinctiveringdetection || p->use_callerid == 1) { ! if(p->use_callerid == 1) { ! cs = callerid_new(); ! ast_log(LOG_DEBUG,"Using US-style caller ID\n"); ! } ! else cs = NULL; ! if(usedistinctiveringdetection || cs) { #if 1 bump_gains(p); #endif *************** *** 5043,5049 **** i = ZT_IOMUX_READ | ZT_IOMUX_SIGEVENT; if ((res = ioctl(p->subs[index].zfd, ZT_IOMUX, &i))) { ast_log(LOG_WARNING, "I/O MUX failed: %s\n", strerror(errno)); ! callerid_free(cs); ast_hangup(chan); return NULL; } --- 5081,5087 ---- i = ZT_IOMUX_READ | ZT_IOMUX_SIGEVENT; if ((res = ioctl(p->subs[index].zfd, ZT_IOMUX, &i))) { ast_log(LOG_WARNING, "I/O MUX failed: %s\n", strerror(errno)); ! if(cs) callerid_free(cs); ast_hangup(chan); return NULL; } *************** *** 5059,5064 **** --- 5097,5115 ---- break; ++receivedRingT; /* Increment the ringT counter so we can match it against values in zapata.conf for distinctive ring */ + + if(receivedRingT==3) + break; /* More than 3 rings would overrun our test buffer */ + + if(!cs) { /* If we're doing CID detection we break on that, not on the end of ring detect */ + /* Otherwise if all dring values are zero, then there's nothing left to detect */ + for (counter=0; counter < 3; counter++) { + if (p->drings.ringnum[counter].ring[receivedRingT]) + break; + } + if (counter == 3) + break; + } } else if (i & ZT_IOMUX_READ) { res = read(p->subs[index].zfd, buf, sizeof(buf)); if (res < 0) { *************** *** 5076,5087 **** res = -1; break; } ! res = callerid_feed(cs, buf, res, AST_LAW(p)); ! if (res < 0) { ! ast_log(LOG_WARNING, "CallerID feed failed: %s\n", strerror(errno)); ! break; ! } else if (res) ! break; } } if (p->usedistinctiveringdetection == 1) { --- 5127,5140 ---- res = -1; break; } ! if(cs) { ! res = callerid_feed(cs, buf, res, AST_LAW(p)); ! if (res < 0) { ! ast_log(LOG_WARNING, "CallerID feed failed: %s\n", strerror(errno)); ! break; ! } else if (res) ! break; ! } } } if (p->usedistinctiveringdetection == 1) { *************** *** 5109,5115 **** } } } ! if (res == 1) { callerid_get(cs, &name, &number, &flags); if (option_debug) ast_log(LOG_DEBUG, "CallerID number: %s, name: %s, flags=%d\n", number, name, flags); --- 5162,5168 ---- } } } ! if (res == 1 && cs) { callerid_get(cs, &name, &number, &flags); if (option_debug) ast_log(LOG_DEBUG, "CallerID number: %s, name: %s, flags=%d\n", number, name, flags); *************** *** 8715,8721 **** ringc = v->value; sscanf(ringc, "%d,%d,%d", &drings.ringnum[2].ring[0], &drings.ringnum[2].ring[1], &drings.ringnum[2].ring[2]); } else if (!strcasecmp(v->name, "usecallerid")) { ! use_callerid = ast_true(v->value); } else if (!strcasecmp(v->name, "threewaycalling")) { threewaycalling = ast_true(v->value); } else if (!strcasecmp(v->name, "cancallforward")) { --- 8768,8776 ---- ringc = v->value; sscanf(ringc, "%d,%d,%d", &drings.ringnum[2].ring[0], &drings.ringnum[2].ring[1], &drings.ringnum[2].ring[2]); } else if (!strcasecmp(v->name, "usecallerid")) { ! if(!strcasecmp(v->value,"us")) use_callerid=1; ! else if(!strcasecmp(v->value,"uk")) use_callerid=2; ! else use_callerid=ast_true(v->value); } else if (!strcasecmp(v->name, "threewaycalling")) { threewaycalling = ast_true(v->value); } else if (!strcasecmp(v->name, "cancallforward")) { *************** *** 9372,9378 **** ringc = v->value; sscanf(ringc, "%d,%d,%d", &drings.ringnum[2].ring[0], &drings.ringnum[2].ring[1], &drings.ringnum[2].ring[2]); } else if (!strcasecmp(v->name, "usecallerid")) { ! use_callerid = ast_true(v->value); } else if (!strcasecmp(v->name, "threewaycalling")) { threewaycalling = ast_true(v->value); } else if (!strcasecmp(v->name, "transfer")) { --- 9427,9435 ---- ringc = v->value; sscanf(ringc, "%d,%d,%d", &drings.ringnum[2].ring[0], &drings.ringnum[2].ring[1], &drings.ringnum[2].ring[2]); } else if (!strcasecmp(v->name, "usecallerid")) { ! if(!strcasecmp(v->value,"us")) use_callerid=1; ! else if(!strcasecmp(v->value,"uk")) use_callerid=2; ! else use_callerid=ast_true(v->value); } else if (!strcasecmp(v->name, "threewaycalling")) { threewaycalling = ast_true(v->value); } else if (!strcasecmp(v->name, "transfer")) {