Index: channels/chan_agent.c =================================================================== --- channels/chan_agent.c (revision 8055) +++ channels/chan_agent.c (working copy) @@ -494,7 +494,7 @@ } else { /* if acknowledgement is not required, and the channel is up, we may have missed an AST_CONTROL_ANSWER (if there was one), so mark the call acknowledged anyway */ - if (!p->ackcall && !p->acknowledged && p->chan && (p->chan->_state == AST_STATE_UP)) + if (!p->acknowledged && !p->ackcall && p->chan && (p->chan->_state == AST_STATE_UP)) p->acknowledged = 1; switch (f->frametype) { case AST_FRAME_CONTROL: @@ -541,8 +541,7 @@ if (p->chan && !p->chan->_bridge) { if (strcasecmp(p->chan->type, "Local")) { p->chan->_bridge = ast; - if (p->chan) - ast_log(LOG_DEBUG, "Bridge on '%s' being set to '%s' (3)\n", p->chan->name, p->chan->_bridge->name); + ast_log(LOG_DEBUG, "Bridge on '%s' being set to '%s' (3)\n", p->chan->name, p->chan->_bridge->name); } } ast_mutex_unlock(&p->lock); @@ -611,12 +610,10 @@ static int agent_indicate(struct ast_channel *ast, int condition) { struct agent_pvt *p = ast->tech_pvt; - int res = -1; + int res = 0; ast_mutex_lock(&p->lock); if (p->chan) res = ast_indicate(p->chan, condition); - else - res = 0; ast_mutex_unlock(&p->lock); return res; } @@ -624,12 +621,10 @@ static int agent_digit(struct ast_channel *ast, char digit) { struct agent_pvt *p = ast->tech_pvt; - int res = -1; + int res = 0; ast_mutex_lock(&p->lock); if (p->chan) res = p->chan->tech->send_digit(p->chan, digit); - else - res = 0; ast_mutex_unlock(&p->lock); return res; } @@ -638,21 +633,18 @@ { struct agent_pvt *p = ast->tech_pvt; int res = -1; - int newstate=0; ast_mutex_lock(&p->lock); p->acknowledged = 0; if (!p->chan) { if (p->pending) { ast_log(LOG_DEBUG, "Pretending to dial on pending agent\n"); - newstate = AST_STATE_DIALING; + ast_setstate(ast, AST_STATE_DIALING); res = 0; } else { ast_log(LOG_NOTICE, "Whoa, they hung up between alloc and call... what are the odds of that?\n"); res = -1; } ast_mutex_unlock(&p->lock); - if (newstate) - ast_setstate(ast, newstate); return res; } else if (!ast_strlen_zero(p->loginchan)) { time(&p->start); @@ -690,7 +682,7 @@ } if (!res) { - ast_set_write_format(p->chan, ast_best_codec(p->chan->nativeformats)); + res = ast_set_write_format(p->chan, ast_best_codec(p->chan->nativeformats)); ast_log( LOG_DEBUG, "Set write format, result '%d'\n", res); if (res) ast_log(LOG_WARNING, "Unable to set write format to %s\n", ast_getformatname(ast_best_codec(p->chan->nativeformats))); @@ -699,19 +691,16 @@ { /* Call is immediately up, or might need ack */ if (p->ackcall > 1) - newstate = AST_STATE_RINGING; + ast_setstate(ast, AST_STATE_RINGING); else { - newstate = AST_STATE_UP; + ast_setstate(ast, AST_STATE_UP); if (recordagentcalls) agent_start_monitoring(ast,0); p->acknowledged = 1; } - res = 0; } CLEANUP(ast,p); ast_mutex_unlock(&p->lock); - if (newstate) - ast_setstate(ast, newstate); return res; } @@ -2180,11 +2169,6 @@ return 0; } - if (ast_strlen_zero(exten)) { - astman_send_error(s, m, "No extension specified"); - return 0; - } - ast_mutex_lock(&agentlock); p = agents; while(p) { @@ -2199,10 +2183,7 @@ ast_mutex_lock(&p->lock); login_state = 1; /* Successful Login */ - if (ast_strlen_zero(context)) - ast_copy_string(p->loginchan, exten, sizeof(p->loginchan)); - else - snprintf(p->loginchan, sizeof(p->loginchan), "%s@%s", exten, context); + snprintf(p->loginchan, sizeof(p->loginchan), "%s@%s", exten, !ast_strlen_zero(context) ? context : "default"); if (!ast_strlen_zero(wrapuptime_s)) { p->wrapuptime = atoi(wrapuptime_s); @@ -2210,7 +2191,9 @@ p->wrapuptime = 0; } - if (ast_true(ackcall_s)) + if (!strcasecmp(ackcall_s, "always")) + p->ackcall = 2; + else if (ast_true(ackcall_s)) p->ackcall = 1; else p->ackcall = 0;