mirror of
https://github.com/asterisk/asterisk.git
synced 2025-09-06 12:36:58 +00:00
Made chan_agent code parsing more robust and
implemented new macro code. from 6228. git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@8064 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
@@ -288,17 +288,17 @@ static void agent_unlink(struct agent_pvt *agent)
|
|||||||
struct agent_pvt *p, *prev;
|
struct agent_pvt *p, *prev;
|
||||||
prev = NULL;
|
prev = NULL;
|
||||||
p = agents;
|
p = agents;
|
||||||
// Iterate over all agents looking for the one.
|
/* Iterate over all agents looking for the one. */
|
||||||
while(p) {
|
while(p) {
|
||||||
if (p == agent) {
|
if (p == agent) {
|
||||||
// Once it wal found, check if it is the first one.
|
/* Once it was found, check if it is the first one. */
|
||||||
if (prev)
|
if (prev)
|
||||||
// If it is not, tell the previous agent that the next one is the next one of the current (jumping the current).
|
/* If it is not, tell the previous agent that the next one is the next one of the current (jumping the current). */
|
||||||
prev->next = agent->next;
|
prev->next = agent->next;
|
||||||
else
|
else
|
||||||
// If it is the first one, just change the general pointer to point to the second one.
|
/* If it is the first one, just change the general pointer to point to the second one. */
|
||||||
agents = agent->next;
|
agents = agent->next;
|
||||||
// We are done.
|
/* We are done. */
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
prev = p;
|
prev = p;
|
||||||
@@ -316,32 +316,47 @@ static void agent_unlink(struct agent_pvt *agent)
|
|||||||
*/
|
*/
|
||||||
static struct agent_pvt *add_agent(char *agent, int pending)
|
static struct agent_pvt *add_agent(char *agent, int pending)
|
||||||
{
|
{
|
||||||
int argc;
|
char *parse;
|
||||||
char *argv[3];
|
AST_DECLARE_APP_ARGS(args,
|
||||||
char *args;
|
AST_APP_ARG(agt);
|
||||||
|
AST_APP_ARG(password);
|
||||||
|
AST_APP_ARG(name);
|
||||||
|
);
|
||||||
char *password = NULL;
|
char *password = NULL;
|
||||||
char *name = NULL;
|
char *name = NULL;
|
||||||
char *agt = NULL;
|
char *agt = NULL;
|
||||||
struct agent_pvt *p, *prev;
|
struct agent_pvt *p, *prev;
|
||||||
|
|
||||||
args = ast_strdupa(agent);
|
parse = ast_strdupa(agent);
|
||||||
|
if (!parse) {
|
||||||
|
ast_log(LOG_ERROR, "Out of memory!\n");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
// Extract username (agt), password and name from agent (args).
|
/* Extract username (agt), password and name from agent (args). */
|
||||||
if ((argc = ast_app_separate_args(args, ',', argv, sizeof(argv) / sizeof(argv[0])))) {
|
AST_NONSTANDARD_APP_ARGS(args, parse, ',');
|
||||||
agt = argv[0];
|
|
||||||
if (argc > 1) {
|
if(args.argc == 0) {
|
||||||
password = argv[1];
|
ast_log(LOG_WARNING, "A blank agent line!\n");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(ast_strlen_zero(args.agt) ) {
|
||||||
|
ast_log(LOG_WARNING, "An agent line with no agentid!\n");
|
||||||
|
return NULL;
|
||||||
|
} else
|
||||||
|
agt = args.agt;
|
||||||
|
|
||||||
|
if(!ast_strlen_zero(args.password)) {
|
||||||
|
password = args.password;
|
||||||
while (*password && *password < 33) password++;
|
while (*password && *password < 33) password++;
|
||||||
}
|
}
|
||||||
if (argc > 2) {
|
if(!ast_strlen_zero(args.name)) {
|
||||||
name = argv[2];
|
name = args.name;
|
||||||
while (*name && *name < 33) name++;
|
while (*name && *name < 33) name++;
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
ast_log(LOG_WARNING, "A blank agent line!\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Are we searching for the agent here ? to see if it exists already ?
|
/* Are we searching for the agent here ? To see if it exists already ? */
|
||||||
prev=NULL;
|
prev=NULL;
|
||||||
p = agents;
|
p = agents;
|
||||||
while(p) {
|
while(p) {
|
||||||
|
@@ -228,6 +228,19 @@ int ast_app_group_match_get_count(const char *groupmatch, const char *category);
|
|||||||
#define AST_STANDARD_APP_ARGS(args, parse) \
|
#define AST_STANDARD_APP_ARGS(args, parse) \
|
||||||
args.argc = ast_app_separate_args(parse, '|', args.argv, (sizeof(args) - sizeof(args.argc)) / sizeof(args.argv[0]))
|
args.argc = ast_app_separate_args(parse, '|', args.argv, (sizeof(args) - sizeof(args.argc)) / sizeof(args.argv[0]))
|
||||||
|
|
||||||
|
/*!
|
||||||
|
\brief Performs the 'nonstandard' argument separation process for an application.
|
||||||
|
\param args An argument structure defined using AST_DECLARE_APP_ARGS
|
||||||
|
\param parse A modifiable buffer containing the input to be parsed
|
||||||
|
\param sep A nonstandard separator character
|
||||||
|
|
||||||
|
This function will separate the input string using the nonstandard argument
|
||||||
|
separator character and fill in the provided structure, including
|
||||||
|
the argc argument counter field.
|
||||||
|
*/
|
||||||
|
#define AST_NONSTANDARD_APP_ARGS(args, parse, sep) \
|
||||||
|
args.argc = ast_app_separate_args(parse, sep, args.argv, (sizeof(args) - sizeof(args.argc)) / sizeof(args.argv[0]))
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief Separate a string into arguments in an array
|
\brief Separate a string into arguments in an array
|
||||||
\param buf The string to be parsed (this must be a writable copy, as it will be modified)
|
\param buf The string to be parsed (this must be a writable copy, as it will be modified)
|
||||||
|
Reference in New Issue
Block a user