--- /home/matt/dev/asterisk/channels/chan_agent.c 2004-05-10 16:06:28.000000000 +0000 +++ asterisk/channels/chan_agent.c 2004-05-11 17:59:13.000000000 +0000 @@ -1102,6 +1102,63 @@ return RESULT_SUCCESS; } +static int agent_logoff(int fd, int argc, char **argv) +{ + struct agent_pvt *p = NULL; + char *line = NULL; + int res = 0; + + /* Check args */ + if (argc != 3) + return RESULT_SHOWUSAGE; + + line = argv[2]; + + ast_mutex_lock(&agentlock); + p = agents; + while (p) { + ast_mutex_lock(&p->lock); + res = strcmp(p->agent, line); + + if (res == 0) { + /* Found him! Now we're going to kill him. */ + if (p->chan) { + if (p->owner && p->owner->bridge) { /* Uh oh, he's on a call right now */ + ast_cli(fd, "Agent %s is on a call right now with %s. Try later.\n", line, p->owner->bridge->name); + ast_mutex_unlock(&p->lock); + break; + } + } + + /* Good, no calls. He won't escape now! */ + if (ast_strlen_zero(p->loginchan)) { + ast_cli(fd, "Agent %s already logged off the system.\n", line); + ast_mutex_unlock(&p->lock); + break; + } + + strcpy(p->loginchan, ""); /* Bang! Killed him */ + ast_cli(fd, "Agent %s successfully logged off.\n", line); + ast_mutex_unlock(&p->lock); + break; + } + + ast_mutex_unlock(&p->lock); + p = p->next; + } + ast_mutex_unlock(&agentlock); + if (res) ast_cli(fd, "Unable to find agent %s.\n", line); + return RESULT_SUCCESS; +} + +static char agent_logoff_usage[] = +"Usage: agent logoff \n" +" Log an agent off the system that maybe forgot to log off, etc....\n"; + +static struct ast_cli_entry cli_agent_logoff = { + { "agent", "logoff", NULL }, agent_logoff, + "Log an agent off of the system", agent_logoff_usage, NULL}; + static char show_agents_usage[] = "Usage: show agents\n" " Provides summary information on agents.\n"; @@ -1479,6 +1536,7 @@ ast_register_application(app2, callback_exec, synopsis2, descrip2); ast_register_application(app3, agentmonitoroutgoing_exec, synopsis3, descrip3); ast_cli_register(&cli_show_agents); + ast_cli_register(&cli_agent_logoff); /* Read in the config */ read_agent_config(); return 0;