use arg parsing macros in the AGENT dialplan function (issue #6236, with small mods)

git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@8676 65c4cc65-6c06-0410-ace0-fbb531ad65f3
1.4
Russell Bryant 20 years ago
parent 778acbff12
commit 19f99bee0f

@ -2417,8 +2417,11 @@ struct agent_pvt *find_agent(char *agentid)
static char *function_agent(struct ast_channel *chan, char *cmd, char *data, char *buf, size_t len) static char *function_agent(struct ast_channel *chan, char *cmd, char *data, char *buf, size_t len)
{ {
char *agentid; char *parse;
char *item; AST_DECLARE_APP_ARGS(args,
AST_APP_ARG(agentid);
AST_APP_ARG(item);
);
char *tmp; char *tmp;
struct agent_pvt *agent; struct agent_pvt *agent;
@ -2429,39 +2432,38 @@ static char *function_agent(struct ast_channel *chan, char *cmd, char *data, cha
return buf; return buf;
} }
if (!(item = ast_strdupa(data))) if (!(parse = ast_strdupa(data)))
return buf; return buf;
agentid = strsep(&item, ":"); AST_NONSTANDARD_APP_ARGS(args, parse, ':');
if (!item) if (!args.item)
item = "status"; args.item = "status";
agent = find_agent(agentid); if (!(agent = find_agent(args.agentid))) {
if (!agent) { ast_log(LOG_WARNING, "Agent '%s' not found!\n", args.agentid);
ast_log(LOG_WARNING, "Agent '%s' not found!\n", agentid);
return buf; return buf;
} }
if (!strcasecmp(item, "status")) { if (!strcasecmp(args.item, "status")) {
if (agent->chan || !ast_strlen_zero(agent->loginchan)) { if (agent->chan || !ast_strlen_zero(agent->loginchan)) {
ast_copy_string(buf, "LOGGEDIN", len); ast_copy_string(buf, "LOGGEDIN", len);
} else { } else {
ast_copy_string(buf, "LOGGEDOUT", len); ast_copy_string(buf, "LOGGEDOUT", len);
} }
} else if (!strcasecmp(item, "password")) { } else if (!strcasecmp(args.item, "password")) {
ast_copy_string(buf, agent->password, len); ast_copy_string(buf, agent->password, len);
} else if (!strcasecmp(item, "name")) { } else if (!strcasecmp(args.item, "name")) {
ast_copy_string(buf, agent->name, len); ast_copy_string(buf, agent->name, len);
} else if (!strcasecmp(item, "mohclass")) { } else if (!strcasecmp(args.item, "mohclass")) {
ast_copy_string(buf, agent->moh, len); ast_copy_string(buf, agent->moh, len);
} else if (!strcasecmp(item, "channel")) { } else if (!strcasecmp(args.item, "channel")) {
if (agent->chan) { if (agent->chan) {
ast_copy_string(buf, agent->chan->name, len); ast_copy_string(buf, agent->chan->name, len);
tmp = strrchr(buf, '-'); tmp = strrchr(buf, '-');
if (tmp) if (tmp)
*tmp = '\0'; *tmp = '\0';
} }
} else if (!strcasecmp(item, "exten")) { } else if (!strcasecmp(args.item, "exten")) {
ast_copy_string(buf, agent->loginchan, len); ast_copy_string(buf, agent->loginchan, len);
} }

Loading…
Cancel
Save