[asterisk-commits] file: branch file/app_agents r140553 - /team/file/app_agents/apps/app_agents.c
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Sun Aug 31 20:33:08 CDT 2008
Author: file
Date: Sun Aug 31 20:33:08 2008
New Revision: 140553
URL: http://svn.digium.com/view/asterisk?view=rev&rev=140553
Log:
Add a few application options.
Modified:
team/file/app_agents/apps/app_agents.c
Modified: team/file/app_agents/apps/app_agents.c
URL: http://svn.digium.com/view/asterisk/team/file/app_agents/apps/app_agents.c?view=diff&rev=140553&r1=140552&r2=140553
==============================================================================
--- team/file/app_agents/apps/app_agents.c (original)
+++ team/file/app_agents/apps/app_agents.c Sun Aug 31 20:33:08 2008
@@ -92,13 +92,17 @@
static const char app[] = "AgentLogin2";
static const char synopsis[] = "Call Agent Login";
static const char descrip[] =
-" AgentLogin2():\n"
-"Asks the agent to login to the system. Always returns -1.";
+" AgentLogin2([Agent Name][,options]):\n"
+"Asks the agent to login to the system. Always returns -1."
+"The option string may contain zero or more of the following characters:\n"
+" l -- force logout - this will log out a callback agent if logged in\n"
+" u -- skip pin - do not authenticate the agent\n"
+" s -- silent - do not play login or logoff sound files\n";
static const char app2[] = "AgentCall2";
static const char synopsis2[] = "Talk to an agent";
static const char descrip2[] =
-" AgentCall2(agent name):\n"
+" AgentCall2(Agent Name):\n"
"Attempts to talk to the given agent. Always returns -1.";
/*! \brief State that the agent should be in */
@@ -141,6 +145,20 @@
struct ast_dial *dial; /*!< Dialing structure used for callback agents */
};
+/*! \brief Flags used for login application arguments */
+enum {
+ OPTION_LOGIN_LOGOUT = (1 << 0), /*!< Force log out of the agent */
+ OPTION_LOGIN_SKIP_PIN = (1 << 1), /*!< Do not ask the agent to enter a pin */
+ OPTION_LOGIN_SILENT = (1 << 2), /*!< Do not announce that the login logged in or logged out */
+} login_option_flags;
+
+/*! \brief Options for login application */
+AST_APP_OPTIONS(login_options, {
+ AST_APP_OPTION('l', OPTION_LOGIN_LOGOUT),
+ AST_APP_OPTION('u', OPTION_LOGIN_SKIP_PIN),
+ AST_APP_OPTION('s', OPTION_LOGIN_SILENT),
+});
+
/*! \brief Container to hold agents */
static struct ao2_container *agents;
@@ -252,7 +270,7 @@
}
/*! \brief Function called to log in a waiter agent */
-static void agent2_waiter_login(struct agent2_agent *agent, struct ast_channel *chan)
+static void agent2_waiter_login(struct agent2_agent *agent, struct ast_channel *chan, int silent)
{
struct timeval login_time;
long session_duration = 0;
@@ -280,7 +298,9 @@
ast_queue_log("NONE", chan->uniqueid, agent->name, "AGENTLOGIN", "%s", chan->name);
ast_verb(2, "Agent '%s' logged in on '%s'\n", agent->name, chan->name);
- ast_stream_and_wait(chan, "agent-loginok", "");
+ if (!silent) {
+ ast_stream_and_wait(chan, "agent-loginok", "");
+ }
agent2_change_state(agent, AGENT2_STATE_WAIT);
ast_indicate_data(chan, AST_CONTROL_HOLD, S_OR(agent->moh, NULL), !ast_strlen_zero(agent->moh) ? strlen(agent->moh) + 1 : 0);
@@ -371,7 +391,7 @@
}
/*! \brief Function called to log in a callback agent */
-static void agent2_callback_login(struct agent2_agent *agent, struct ast_channel *chan)
+static void agent2_callback_login(struct agent2_agent *agent, struct ast_channel *chan, int silent)
{
/* Try to get the agent to input the destination at which they can be reached */
for (;;) {
@@ -396,7 +416,9 @@
ast_queue_log("NONE", chan->uniqueid, agent->name, "AGENTCALLBACKLOGIN", "%s", chan->name);
ast_verb(2, "Agent '%s' logged in on '%s' available at '%s@%s'\n", agent->name, chan->name, agent->location, S_OR(agent->context, "default"));
- ast_stream_and_wait(chan, "agent-loginok", "");
+ if (!silent) {
+ ast_stream_and_wait(chan, "agent-loginok", "");
+ }
agent2_change_state(agent, AGENT2_STATE_WAIT);
/* If the agent has persistency enabled write this data out to the astdb */
@@ -408,7 +430,7 @@
}
/*! \brief Function called to log off a callback agent */
-static void agent2_callback_logoff(struct agent2_agent *agent, struct ast_channel *chan)
+static void agent2_callback_logoff(struct agent2_agent *agent, struct ast_channel *chan, int silent)
{
/* Make it known this callback agent logged off */
manager_event(EVENT_FLAG_AGENT, "AgentCallbackLogoff",
@@ -419,7 +441,9 @@
ast_queue_log("NONE", chan->uniqueid, agent->name, "AGENTCALLBACKLOGOFF", "%s", chan->name);
ast_verb(2, "Agent '%s' logged out\n", agent->name);
- ast_stream_and_wait(chan, "agent-loggedoff", "");
+ if (!silent) {
+ ast_stream_and_wait(chan, "agent-loggedoff", "");
+ }
agent2_change_state(agent, AGENT2_STATE_NONE);
/* If the agent has persistency enabled delete their record */
@@ -433,6 +457,12 @@
/*! \brief Function called to log in as an agent */
static int agent2_login(struct ast_channel *chan, void *data)
{
+ struct ast_flags flags = { 0, };
+ char *parse;
+ AST_DECLARE_APP_ARGS(args,
+ AST_APP_ARG(agent_name);
+ AST_APP_ARG(options);
+ );
int res, attempts = 0;
struct agent2_agent *agent;
@@ -441,12 +471,23 @@
ast_answer(chan);
}
+ /* Parse out the agent name or options if present */
+ if (!ast_strlen_zero(data)) {
+ parse = ast_strdupa(data);
+ AST_STANDARD_APP_ARGS(args, parse);
+ if (args.argc == 2) {
+ ast_app_parse_options(login_options, &flags, NULL, args.options);
+ }
+ }
+
do {
struct agent2_agent tmp;
int max_tries = MAX_PIN_TRIES;
/* Try to get an agent name */
- if ((res = ast_app_getdata(chan, attempts ? "agent-incorrect" : "agent-user", tmp.name, sizeof(tmp.name) - 1, 0))) {
+ if (!ast_strlen_zero(args.agent_name)) {
+ ast_copy_string(tmp.name, args.agent_name, sizeof(tmp.name));
+ } else if ((res = ast_app_getdata(chan, attempts ? "agent-incorrect" : "agent-user", tmp.name, sizeof(tmp.name) - 1, 0))) {
return res;
}
@@ -456,7 +497,7 @@
}
/* Go for the actual PIN number now */
- if ((res = ast_app_getdata(chan, "agent-pass", tmp.pin, sizeof(tmp.pin) - 1, 0))) {
+ if (!ast_test_flag(&flags, OPTION_LOGIN_SKIP_PIN) && (res = ast_app_getdata(chan, "agent-pass", tmp.pin, sizeof(tmp.pin) - 1, 0))) {
if (agent) {
ao2_ref(agent, -1);
}
@@ -464,7 +505,7 @@
}
if (agent) {
- if (!strcasecmp(agent->pin, tmp.pin)) {
+ if (ast_test_flag(&flags, OPTION_LOGIN_SKIP_PIN) || !strcasecmp(agent->pin, tmp.pin)) {
break;
}
ao2_ref(agent, -1);
@@ -480,12 +521,12 @@
/* Bounce it off to the right login or logoff function */
if (agent->type == AGENT2_TYPE_WAITER) {
- agent2_waiter_login(agent, chan);
+ agent2_waiter_login(agent, chan, ast_test_flag(&flags, OPTION_LOGIN_SILENT));
} else if (agent->type == AGENT2_TYPE_CALLBACK) {
- if (agent->state == AGENT2_STATE_NONE) {
- agent2_callback_login(agent, chan);
+ if (!ast_test_flag(&flags, OPTION_LOGIN_LOGOUT) && agent->state == AGENT2_STATE_NONE) {
+ agent2_callback_login(agent, chan, ast_test_flag(&flags, OPTION_LOGIN_SILENT));
} else {
- agent2_callback_logoff(agent, chan);
+ agent2_callback_logoff(agent, chan, ast_test_flag(&flags, OPTION_LOGIN_SILENT));
}
}
@@ -753,16 +794,16 @@
CV_START(var->name, var->value);
CV_STR("pin", agent->pin);
CV_STR("musiconhold", agent->moh);
- CV_F("endcall", agent->endcall = ast_true(var->value));
+ CV_BOOL("endcall", agent->endcall);
CV_F("wrapuptime", agent->wrapuptime = atoi(var->value));
CV_STR("sound_beep", agent->beep);
CV_F("maxtries", agent->maxtries = atoi(var->value));
- CV_F("record", agent->record = ast_true(var->value));
+ CV_BOOL("record", agent->record);
CV_STR("record_format", agent->record_format);
CV_STR("record_directory", agent->record_directory);
CV_F("type", agent->type = !strcasecmp(var->value, "callback") ? AGENT2_TYPE_CALLBACK : AGENT2_TYPE_WAITER);
- CV_F("ackcall", agent->ackcall = ast_true(var->value));
- CV_F("persist", agent->persist = ast_true(var->value));
+ CV_BOOL("ackcall", agent->ackcall);
+ CV_BOOL("persist", agent->persist);
CV_STR("context", agent->context);
CV_END;
}
More information about the asterisk-commits
mailing list