--- /root/cvs/2/asterisk/channels/chan_agent.c 2004-08-11 15:02:46.000000000 -0400 +++ chan_agent.c 2004-09-18 21:45:16.946032938 -0400 @@ -1,3 +1,4 @@ + /* * Asterisk -- A telephony toolkit for Linux. * @@ -78,6 +79,7 @@ " 'n' - don't generate the warnings when there is no callerid or the agentid is not known. It's handy if you want to have one context for agent and non-agent calls.\n"; static char moh[80] = "default"; +static char preackannounce[80]; /* Pre Acknowledgement Announcement to play */ #define AST_MAX_AGENT 80 /* Agent ID or Password max length */ #define AST_MAX_BUF 256 @@ -88,6 +90,7 @@ static int autologoff; static int wrapuptime; static int ackcall; +static int preack; static int usecnt =0; AST_MUTEX_DEFINE_STATIC(usecnt_lock); @@ -113,6 +116,7 @@ int abouttograb; /* About to grab */ int autologoff; /* Auto timeout time */ int ackcall; /* ackcall */ + int preack; /* If we have a preackannounce file */ time_t loginstart; /* When agent first logged in (0 when logged off) */ time_t start; /* When call started */ struct timeval lastdisc; /* When last disconnected */ @@ -233,6 +237,7 @@ strncpy(p->name, name ? name : "", sizeof(p->name) - 1); strncpy(p->moh, moh, sizeof(p->moh) - 1); p->ackcall = ackcall; + p->preack = preack; p->autologoff = autologoff; p->wrapuptime = wrapuptime; if (pending) @@ -276,7 +281,7 @@ if (!p) return -1; if (!ast->monitor) { - snprintf(filename, sizeof(filename), "agent-%s-%s",p->agent, ast->uniqueid); + snprintf(filename, sizeof(filename), "agent-%s-%s",p->agent, ast->callerid); /* substitute . for - */ if ((pointer = strchr(filename, '.'))) *pointer = '-'; @@ -303,7 +308,9 @@ static struct ast_frame *agent_read(struct ast_channel *ast) { - struct agent_pvt *p = ast->pvt->pvt; + int res = -1; + int digit = 0; + struct agent_pvt *p = ast->pvt->pvt; struct ast_frame *f = NULL; static struct ast_frame null_frame = { AST_FRAME_NULL, }; static struct ast_frame answer_frame = { AST_FRAME_CONTROL, AST_CONTROL_ANSWER }; @@ -340,20 +347,43 @@ } } if (f && (f->frametype == AST_FRAME_CONTROL) && (f->subclass == AST_CONTROL_ANSWER)) { + /* TC */ if (p->ackcall) { - if (option_verbose > 2) - ast_verbose(VERBOSE_PREFIX_3 "%s answered, waiting for '#' to acknowledge\n", p->chan->name); + if (p->preack == 1) + { + res = ast_safe_sleep(p->chan, 1000); /* Let the agent get the phone to his ear */ + res = 0; + ast_stopstream(p->chan); + res = ast_streamfile(p->chan, preackannounce, p->chan->language); + if (!res) + digit = ast_waitstream(p->chan, "*#"); + else + { + + ast_verbose(VERBOSE_PREFIX_3 "ast_streamfile failed on %s\n", p->chan->name); + res = 0; + } + ast_stopstream(p->chan); + } + + if (option_verbose > 2) + ast_verbose(VERBOSE_PREFIX_3 "%s answered, waiting for '#' to acknowledge\n", p->chan->name); /* Don't pass answer along */ ast_frfree(f); f = &null_frame; } + else { p->acknowledged = 1; f = &answer_frame; } } - if (f && (f->frametype == AST_FRAME_DTMF) && (f->subclass == '#')) { + if (digit > 0) { + f->frametype = AST_FRAME_DTMF; + f->subclass = digit; + } + if (f && (f->frametype == AST_FRAME_DTMF) && (f->subclass == '#')) { if (!p->acknowledged) { if (option_verbose > 2) ast_verbose(VERBOSE_PREFIX_3 "%s acknowledged\n", p->chan->name); @@ -362,7 +392,7 @@ f = &answer_frame; } } - if (f && (f->frametype == AST_FRAME_DTMF) && (f->subclass == '*')) { + if (f && (f->frametype == AST_FRAME_DTMF) && (f->subclass == '*')) { /* * terminates call */ ast_frfree(f); f = NULL; @@ -787,6 +817,7 @@ autologoff = 0; wrapuptime = 0; ackcall = 1; + preack = 1; cfg = ast_load(config); if (!cfg) { ast_log(LOG_NOTICE, "No agent configuration found -- agent support disabled\n"); @@ -822,13 +853,16 @@ if (!strcasecmp(v->value, "always")) ackcall = 2; else if (ast_true(v->value)) - ackcall = 1; + ackcall = 1; else ackcall = 0; } else if (!strcasecmp(v->name, "wrapuptime")) { wrapuptime = atoi(v->value); if (wrapuptime < 0) wrapuptime = 0; + } else if (!strcasecmp(v->name, "preackannounce")) { + strncpy(preackannounce, v->value, sizeof(preackannounce) - 1); + preack = 1; } else if (!strcasecmp(v->name, "musiconhold")) { strncpy(moh, v->value, sizeof(moh) - 1); } else if (!strcasecmp(v->name, "updatecdr")) { @@ -1029,10 +1063,10 @@ /* Fixed agent */ chan = agent_new(p, AST_STATE_DOWN); } - if (chan) { + /* if (chan) { ast_mutex_unlock(&p->lock); break; - } + } */ } } ast_mutex_unlock(&p->lock);