diff options
author | markster <markster@f38db490-d61c-443f-a65b-d21fe96a405b> | 2005-04-15 05:51:30 +0000 |
---|---|---|
committer | markster <markster@f38db490-d61c-443f-a65b-d21fe96a405b> | 2005-04-15 05:51:30 +0000 |
commit | c8376197df0c413e492412d149e9bf3592a9ff2e (patch) | |
tree | 2b4718bec12b9a9a734d3c9759e9dbd784925a32 /channels | |
parent | e9f1e11585cabd23492795d1bc82ad6d1d94afae (diff) |
Fix "show agents" when name is not present (bug #4030)
git-svn-id: http://svn.digium.com/svn/asterisk/trunk@5470 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'channels')
-rwxr-xr-x | channels/chan_agent.c | 46 |
1 files changed, 28 insertions, 18 deletions
diff --git a/channels/chan_agent.c b/channels/chan_agent.c index 89fc396e4..38d6f6deb 100755 --- a/channels/chan_agent.c +++ b/channels/chan_agent.c @@ -245,25 +245,34 @@ static void agent_unlink(struct agent_pvt *agent) static struct agent_pvt *add_agent(char *agent, int pending) { - char tmp[AST_MAX_BUF] = ""; - char *password=NULL, *name=NULL; + int argc; + char *argv[3]; + char *args; + char *password = NULL; + char *name = NULL; + char *agt = NULL; struct agent_pvt *p, *prev; - - strncpy(tmp, agent, sizeof(tmp) - 1); - if ((password = strchr(tmp, ','))) { - *password = '\0'; - password++; - while (*password < 33) password++; - } - if (password && (name = strchr(password, ','))) { - *name = '\0'; - name++; - while (*name < 33) name++; + + args = ast_strdupa(agent); + + if ((argc = ast_separate_app_args(args, ',', argv, sizeof(argv) / sizeof(argv[0])))) { + agt = argv[0]; + if (argc > 1) { + password = argv[1]; + while (*password && *password < 33) password++; + } + if (argc > 2) { + name = argv[2]; + while (*name && *name < 33) name++; + } + } else { + ast_log(LOG_WARNING, "A blank agent line!\n"); } + prev=NULL; p = agents; while(p) { - if (!pending && !strcmp(p->agent, tmp)) + if (!pending && !strcmp(p->agent, agt)) break; prev = p; p = p->next; @@ -272,7 +281,7 @@ static struct agent_pvt *add_agent(char *agent, int pending) p = malloc(sizeof(struct agent_pvt)); if (p) { memset(p, 0, sizeof(struct agent_pvt)); - strncpy(p->agent, tmp, sizeof(p->agent) -1); + strncpy(p->agent, agt, sizeof(p->agent) -1); ast_mutex_init(&p->lock); ast_mutex_init(&p->app_lock); p->owning_app = (pthread_t) -1; @@ -285,12 +294,13 @@ static struct agent_pvt *add_agent(char *agent, int pending) else agents = p; + } else { + return NULL; } } - if (!p) - return NULL; + strncpy(p->password, password ? password : "", sizeof(p->password) - 1); - strncpy(p->name, name ? name : "", sizeof(p->name) - 1); + strncpy(p->name, !ast_strlen_zero(name) ? name : "---", sizeof(p->name) - 1); strncpy(p->moh, moh, sizeof(p->moh) - 1); p->ackcall = ackcall; p->autologoff = autologoff; |