[Asterisk-cvs] asterisk/channels chan_agent.c,1.108,1.109

markster at lists.digium.com markster at lists.digium.com
Sun Jan 30 00:53:36 CST 2005


Update of /usr/cvsroot/asterisk/channels
In directory mongoose.digium.com:/tmp/cvs-serv28830/channels

Modified Files:
	chan_agent.c 
Log Message:
Add agent logon/logoff CLI command (bug #3440)


Index: chan_agent.c
===================================================================
RCS file: /usr/cvsroot/asterisk/channels/chan_agent.c,v
retrieving revision 1.108
retrieving revision 1.109
diff -u -d -r1.108 -r1.109
--- chan_agent.c	25 Jan 2005 06:10:19 -0000	1.108
+++ chan_agent.c	30 Jan 2005 06:55:10 -0000	1.109
@@ -1289,6 +1289,54 @@
 	return 0;
 }
 
+static int agent_logoff_cmd(int fd, int argc, char **argv)
+{
+	struct agent_pvt *p;
+	char *agent = argv[2] + 6;
+
+	if (argc < 3 || argc > 4)
+		return RESULT_SHOWUSAGE;
+	if (argc == 4 && strcasecmp(argv[3], "soft"))
+		return RESULT_SHOWUSAGE;
+
+	for (p=agents; p; p=p->next) {
+		if (!strcasecmp(p->agent, agent)) {
+			if (argc == 3) {
+				if (p->owner) {
+					ast_softhangup(p->owner, AST_SOFTHANGUP_EXPLICIT);
+				}
+				if (p->chan) {
+					ast_softhangup(p->chan, AST_SOFTHANGUP_EXPLICIT);
+				}
+			}
+			p->loginchan[0] = '\0';
+			ast_cli(fd, "Logging out %s\n", agent);
+			break;
+		}
+	}
+	return RESULT_SUCCESS;
+}
+
+static char *complete_agent_logoff_cmd(char *line, char *word, int pos, int state)
+{
+	struct agent_pvt *p;
+	char name[AST_MAX_AGENT];
+	int which = 0;
+
+	if (pos == 2) {
+		for (p=agents; p; p=p->next) {
+			snprintf(name, sizeof(name), "Agent/%s", p->agent);
+			if (!strncasecmp(word, name, strlen(word))) {
+				if (++which > state) {
+					return strdup(name);
+				}
+			}
+		}
+	} else if (pos == 3 && state == 0) {
+		return strdup("soft");
+	}
+	return NULL;
+}
 
 /*--- agents_show: Show agents in cli ---*/
 static int agents_show(int fd, int argc, char **argv)
@@ -1347,10 +1395,19 @@
 "Usage: show agents\n"
 "       Provides summary information on agents.\n";
 
+static char agent_logoff_usage[] =
+"Usage: agent logoff <channel> [soft]\n"
+"       Sets an agent as no longer logged in.\n"
+"       If 'soft' is specified, do not hangup existing calls.\n";
+
 static struct ast_cli_entry cli_show_agents = {
 	{ "show", "agents", NULL }, agents_show, 
 	"Show status of agents", show_agents_usage, NULL };
 
+static struct ast_cli_entry cli_agent_logoff = {
+	{ "agent", "logoff", NULL }, agent_logoff_cmd, 
+	"Sets an agent offline", agent_logoff_usage, complete_agent_logoff_cmd };
+
 STANDARD_LOCAL_USER;
 LOCAL_USER_DECL;
 
@@ -2026,6 +2083,7 @@
 	ast_manager_register2("Agents", 0, action_agents, "Agents", mandescr_agents);
 	/* CLI Application */
 	ast_cli_register(&cli_show_agents);
+	ast_cli_register(&cli_agent_logoff);
 	/* Read in the config */
 	read_agent_config();
 	if (persistent_agents)
@@ -2047,6 +2105,7 @@
 	/* First, take us out of the channel loop */
 	/* Unregister CLI application */
 	ast_cli_unregister(&cli_show_agents);
+	ast_cli_unregister(&cli_agent_logoff);
 	/* Unregister dialplan applications */
 	ast_unregister_application(app);
 	ast_unregister_application(app2);




More information about the svn-commits mailing list