remember CallerID in AgentCallbackLogin, so it can be used at logoff time

use stored CallerID when auto-logoff occurs to clear AGENTBYCALLERID variable (bug #4616)
persist stored CallerID into/out of astdb


git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@6036 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
Kevin P. Fleming
2005-07-06 01:29:15 +00:00
parent 6797e6334f
commit 9403a6e027

View File

@@ -162,7 +162,8 @@ static struct agent_pvt {
volatile pthread_t owning_app; /* Owning application thread id */ volatile pthread_t owning_app; /* Owning application thread id */
volatile int app_sleep_cond; /* Sleep condition for the login app */ volatile int app_sleep_cond; /* Sleep condition for the login app */
struct ast_channel *owner; /* Agent */ struct ast_channel *owner; /* Agent */
char loginchan[80]; char loginchan[80]; /* channel they logged in from */
char logincallerid[80]; /* Caller ID they had when they logged in */
struct ast_channel *chan; /* Channel we use */ struct ast_channel *chan; /* Channel we use */
struct agent_pvt *next; /* Agent */ struct agent_pvt *next; /* Agent */
} *agents = NULL; } *agents = NULL;
@@ -650,6 +651,19 @@ static int agent_call(struct ast_channel *ast, char *dest, int timeout)
return res; return res;
} }
/* store/clear the global variable that stores agentid based on the callerid */
static void set_agentbycallerid(const struct agent_pvt *agent)
{
char buf[AST_MAX_BUF];
/* if there is no Caller ID, nothing to do */
if (!agent->logincallerid[0])
return;
snprintf(buf, sizeof(buf), "%s_%s",GETAGENTBYCALLERID, agent->logincallerid);
pbx_builtin_setvar_helper(NULL, buf, ast_strlen_zero(agent->loginchan) ? NULL : agent->agent);
}
static int agent_hangup(struct ast_channel *ast) static int agent_hangup(struct ast_channel *ast)
{ {
struct agent_pvt *p = ast->tech_pvt; struct agent_pvt *p = ast->tech_pvt;
@@ -715,6 +729,8 @@ static int agent_hangup(struct ast_channel *ast)
snprintf(agent, sizeof(agent), "Agent/%s", p->agent); snprintf(agent, sizeof(agent), "Agent/%s", p->agent);
ast_queue_log("NONE", ast->uniqueid, agent, "AGENTCALLBACKLOGOFF", "%s|%ld|%s", p->loginchan, logintime, "Autologoff"); ast_queue_log("NONE", ast->uniqueid, agent, "AGENTCALLBACKLOGOFF", "%s|%ld|%s", p->loginchan, logintime, "Autologoff");
p->loginchan[0] = '\0'; p->loginchan[0] = '\0';
set_agentbycallerid(p);
p->logincallerid[0] = '\0';
} }
} else if (p->dead) { } else if (p->dead) {
ast_mutex_lock(&p->chan->lock); ast_mutex_lock(&p->chan->lock);
@@ -1404,6 +1420,8 @@ static int agent_logoff_cmd(int fd, int argc, char **argv)
p->agent, p->loginchan, logintime); p->agent, p->loginchan, logintime);
ast_queue_log("NONE", "NONE", agent, "AGENTCALLBACKLOGOFF", "%s|%ld|%s", p->loginchan, logintime, "CommandLogoff"); ast_queue_log("NONE", "NONE", agent, "AGENTCALLBACKLOGOFF", "%s|%ld|%s", p->loginchan, logintime, "CommandLogoff");
p->loginchan[0] = '\0'; p->loginchan[0] = '\0';
set_agentbycallerid(p);
p->logincallerid[0] = '\0';
ast_cli(fd, "Logging out %s\n", agent); ast_cli(fd, "Logging out %s\n", agent);
ast_device_state_changed("Agent/%s", p->agent); ast_device_state_changed("Agent/%s", p->agent);
if (persistent_agents) if (persistent_agents)
@@ -1729,29 +1747,29 @@ static int __login_exec(struct ast_channel *chan, void *data, int callbackmode)
if (context && !ast_strlen_zero(context) && !ast_strlen_zero(tmpchan)) if (context && !ast_strlen_zero(context) && !ast_strlen_zero(tmpchan))
snprintf(p->loginchan, sizeof(p->loginchan), "%s@%s", tmpchan, context); snprintf(p->loginchan, sizeof(p->loginchan), "%s@%s", tmpchan, context);
else { else {
strncpy(last_loginchan, p->loginchan, sizeof(last_loginchan) - 1); ast_copy_string(last_loginchan, p->loginchan, sizeof(last_loginchan));
strncpy(p->loginchan, tmpchan, sizeof(p->loginchan) - 1); ast_copy_string(p->loginchan, tmpchan, sizeof(p->loginchan));
} }
p->acknowledged = 0;
if (ast_strlen_zero(p->loginchan)) { if (ast_strlen_zero(p->loginchan)) {
login_state = 2; login_state = 2;
filename = "agent-loggedoff"; filename = "agent-loggedoff";
} set_agentbycallerid(p);
p->acknowledged = 0; } else {
/* store/clear the global variable that stores agentid based on the callerid */
if (chan->cid.cid_num) { if (chan->cid.cid_num) {
char agentvar[AST_MAX_BUF]; ast_copy_string(p->logincallerid, chan->cid.cid_num, sizeof(p->logincallerid));
snprintf(agentvar, sizeof(agentvar), "%s_%s",GETAGENTBYCALLERID, chan->cid.cid_num); set_agentbycallerid(p);
if (ast_strlen_zero(p->loginchan)) } else
pbx_builtin_setvar_helper(NULL, agentvar, NULL); p->logincallerid[0] = '\0';
else
pbx_builtin_setvar_helper(NULL, agentvar, p->agent);
} }
if(update_cdr && chan->cdr) if(update_cdr && chan->cdr)
snprintf(chan->cdr->channel, sizeof(chan->cdr->channel), "Agent/%s", p->agent); snprintf(chan->cdr->channel, sizeof(chan->cdr->channel), "Agent/%s", p->agent);
} }
} else { } else {
p->loginchan[0] = '\0'; p->loginchan[0] = '\0';
p->logincallerid[0] = '\0';
p->acknowledged = 0; p->acknowledged = 0;
} }
ast_mutex_unlock(&p->lock); ast_mutex_unlock(&p->lock);
@@ -2048,13 +2066,15 @@ static int agentmonitoroutgoing_exec(struct ast_channel *chan, void *data)
static void dump_agents(void) static void dump_agents(void)
{ {
struct agent_pvt *cur_agent = NULL; struct agent_pvt *cur_agent = NULL;
char buf[256];
for (cur_agent = agents; cur_agent; cur_agent = cur_agent->next) { for (cur_agent = agents; cur_agent; cur_agent = cur_agent->next) {
if (cur_agent->chan) if (cur_agent->chan)
continue; continue;
if (!ast_strlen_zero(cur_agent->loginchan)) { if (!ast_strlen_zero(cur_agent->loginchan)) {
if (ast_db_put(pa_family, cur_agent->agent, cur_agent->loginchan)) snprintf(buf, sizeof(buf), "%s;%s", cur_agent->loginchan, cur_agent->logincallerid);
if (ast_db_put(pa_family, cur_agent->agent, buf))
ast_log(LOG_WARNING, "failed to create persistent entry!\n"); ast_log(LOG_WARNING, "failed to create persistent entry!\n");
else if (option_debug) else if (option_debug)
ast_log(LOG_DEBUG, "Saved Agent: %s on %s\n", cur_agent->agent, cur_agent->loginchan); ast_log(LOG_DEBUG, "Saved Agent: %s on %s\n", cur_agent->agent, cur_agent->loginchan);
@@ -2072,7 +2092,10 @@ static void reload_agents(void)
struct ast_db_entry *db_tree; struct ast_db_entry *db_tree;
struct ast_db_entry *entry; struct ast_db_entry *entry;
struct agent_pvt *cur_agent; struct agent_pvt *cur_agent;
char agent_data[80]; char agent_data[256];
char *parse;
char *agent_chan;
char *agent_callerid;
db_tree = ast_db_gettree(pa_family, NULL); db_tree = ast_db_gettree(pa_family, NULL);
@@ -2095,7 +2118,14 @@ static void reload_agents(void)
if (!ast_db_get(pa_family, agent_num, agent_data, sizeof(agent_data)-1)) { if (!ast_db_get(pa_family, agent_num, agent_data, sizeof(agent_data)-1)) {
if (option_debug) if (option_debug)
ast_log(LOG_DEBUG, "Reload Agent: %s on %s\n", cur_agent->agent, agent_data); ast_log(LOG_DEBUG, "Reload Agent: %s on %s\n", cur_agent->agent, agent_data);
strncpy(cur_agent->loginchan, agent_data, sizeof(cur_agent->loginchan)-1); parse = agent_data;
agent_chan = strsep(&parse, ";");
agent_callerid = strsep(&parse, ";");
ast_copy_string(cur_agent->loginchan, agent_chan, sizeof(cur_agent->loginchan));
if (agent_callerid)
ast_copy_string(cur_agent->logincallerid, agent_callerid, sizeof(cur_agent->logincallerid));
else
cur_agent->logincallerid[0] = '\0';
if (cur_agent->loginstart == 0) if (cur_agent->loginstart == 0)
time(&cur_agent->loginstart); time(&cur_agent->loginstart);
ast_device_state_changed("Agent/%s", cur_agent->agent); ast_device_state_changed("Agent/%s", cur_agent->agent);