Index: asterisk/channels/chan_agent.c =================================================================== RCS file: /usr/cvsroot/asterisk/channels/chan_agent.c,v retrieving revision 1.72 diff -c -r1.72 chan_agent.c *** asterisk/channels/chan_agent.c 9 May 2004 07:51:44 -0000 1.72 --- asterisk/channels/chan_agent.c 21 May 2004 09:41:00 -0000 *************** *** 64,76 **** "when a new call comes in. The agent can dump the call by pressing\n" "the star key.\n" "The option string may contain zero or more of the following characters:\n" " 's' -- silent login - do not announce the login ok segment\n"; static char *descrip2 = " AgentCallbackLogin([AgentNo][|[options][exten]@context]):\n" ! "Asks the agent to login to the system with callback. Always returns -1.\n" "The agent's callback extension is called (optionally with the specified\n" ! "context. \n"; static char *descrip3 = " AgentMonitorOutgoing([options]):\n" --- 64,88 ---- "when a new call comes in. The agent can dump the call by pressing\n" "the star key.\n" "The option string may contain zero or more of the following characters:\n" + " 'a-f' - Max Login Attemps (1-6)\n" " 's' -- silent login - do not announce the login ok segment\n"; static char *descrip2 = " AgentCallbackLogin([AgentNo][|[options][exten]@context]):\n" ! "Asks the agent to login to the system with callback.\n" "The agent's callback extension is called (optionally with the specified\n" ! "context. \n" ! "Options: (defaults are 3 login attempts, play announcement, hangup, and return -1)\n" ! "a-f - Max Login Attemps (1-6)\n" ! "g - play goodbye only on login failure\n" ! "G - never play goodbye\n" ! "h - hangup only on login failure (returns -1 on fail or 0 on success)\n" ! "H - never hangug (returns 0)\n" ! "l - hangup when agent logs off overriding option h/H (returns -1)\n" ! "L - hangup when agent logs off overriding option h/H and g/G to play goodbye (returns -1)\n" ! "s - do not play the announcement\n" ! "v - Set Local Variables AGENTNUMBER, AGENTPASS, AGENTEXTEN on successful login\n" ! "V - Same as v - but set the variables globally"; static char *descrip3 = " AgentMonitorOutgoing([options]):\n" *************** *** 1117,1126 **** --- 1129,1140 ---- { int res=0; int tries = 0; + int maxtries = 3; struct agent_pvt *p; struct localuser *u; struct timeval tv; time_t start; + int login_state = 0; char user[AST_MAX_AGENT]; char pass[AST_MAX_AGENT]; char agent[AST_MAX_AGENT] = ""; *************** *** 1129,1137 **** char info[512]; char *opt_user = NULL; char *options = NULL; char *context = NULL; char *exten = NULL; ! int play_announcement; char *filename = "agent-loginok"; LOCAL_USER_ADD(u); --- 1143,1156 ---- char info[512]; char *opt_user = NULL; char *options = NULL; + char option; char *context = NULL; char *exten = NULL; ! int play_announcement = 1; ! int play_goodbye = 1; ! int hangup_call = 1; ! int hangup_logoff = 0; ! int set_vars = 0; char *filename = "agent-loginok"; LOCAL_USER_ADD(u); *************** *** 1156,1161 **** --- 1175,1216 ---- exten = NULL; } } + if( options ) { + while(*options) { + option = (char)options[0]; + if (option=='a') + maxtries = 1; + if (option=='b') + maxtries = 2; + if (option=='c') + maxtries = 3; + if (option=='d') + maxtries = 4; + if (option=='e') + maxtries = 5; + if (option=='f') + maxtries = 6; + if (option=='g') + play_goodbye = 1; + if (option=='G') + play_goodbye = 0; + if (option=='h') + hangup_call = 2; + if (option=='H') + hangup_call = 0; + if (option=='l') + hangup_logoff = 1; + if (option=='L') + hangup_logoff = 2; + if (option=='s') + play_announcement = 0; + if (option=='v') + set_vars = 1; + if (option=='V') + set_vars = 2; + options++; + } + } } if (chan->_state != AST_STATE_UP) *************** *** 1166,1172 **** else res = ast_app_getdata(chan, "agent-user", user, sizeof(user) - 1, 0); } ! while (!res && (tries < 3)) { /* Check for password */ ast_mutex_lock(&agentlock); p = agents; --- 1221,1228 ---- else res = ast_app_getdata(chan, "agent-user", user, sizeof(user) - 1, 0); } ! while (!res && tries < maxtries) { ! tries++; /* Check for password */ ast_mutex_lock(&agentlock); p = agents; *************** *** 1195,1200 **** --- 1251,1257 ---- ast_mutex_lock(&p->lock); if (!strcmp(p->agent, user) && !strcmp(p->password, pass) && !p->pending) { + login_state = 1; /* Successful Login */ if (!p->chan) { if (callbackmode) { char tmpchan[AST_MAX_BUF] = ""; *************** *** 1227,1239 **** } } } if (!res) { if (context && !ast_strlen_zero(context) && !ast_strlen_zero(tmpchan)) snprintf(p->loginchan, sizeof(p->loginchan), "%s@%s", tmpchan, context); else strncpy(p->loginchan, tmpchan, sizeof(p->loginchan) - 1); ! if (ast_strlen_zero(p->loginchan)) filename = "agent-loggedoff"; p->acknowledged = 0; /* store/clear the global variable that stores agentid based on the callerid */ if (chan->callerid) { --- 1284,1299 ---- } } } + exten = tmpchan; if (!res) { if (context && !ast_strlen_zero(context) && !ast_strlen_zero(tmpchan)) snprintf(p->loginchan, sizeof(p->loginchan), "%s@%s", tmpchan, context); else strncpy(p->loginchan, tmpchan, sizeof(p->loginchan) - 1); ! if (ast_strlen_zero(p->loginchan)) { ! login_state = 2; filename = "agent-loggedoff"; + } p->acknowledged = 0; /* store/clear the global variable that stores agentid based on the callerid */ if (chan->callerid) { *************** *** 1252,1261 **** strcpy(p->loginchan, ""); p->acknowledged = 0; } ! play_announcement = 1; ! if( options ) ! if( strchr( options, 's' ) ) ! play_announcement = 0; ast_mutex_unlock(&p->lock); ast_mutex_unlock(&agentlock); if( !res && play_announcement ) --- 1312,1318 ---- strcpy(p->loginchan, ""); p->acknowledged = 0; } ! ast_mutex_unlock(&p->lock); ast_mutex_unlock(&agentlock); if( !res && play_announcement ) *************** *** 1278,1292 **** if (p->chan) res = -1; if (callbackmode && !res) { - /* Just say goodbye and be done with it */ ast_mutex_unlock(&agentlock); if (!res) res = ast_safe_sleep(chan, 500); - res = ast_streamfile(chan, "vm-goodbye", chan->language); - if (!res) - res = ast_waitstream(chan, ""); - if (!res) - res = ast_safe_sleep(chan, 1000); ast_mutex_unlock(&p->lock); } else if (!res) { #ifdef HONOR_MUSIC_CLASS --- 1335,1343 ---- *************** *** 1399,1411 **** if (!p) ast_mutex_unlock(&agentlock); ! if (!res) res = ast_app_getdata(chan, errmsg, user, sizeof(user) - 1, 0); } LOCAL_USER_REMOVE(u); ! /* Always hangup */ ! return -1; } static int login_exec(struct ast_channel *chan, void *data) --- 1450,1492 ---- if (!p) ast_mutex_unlock(&agentlock); ! if (!res && tries < maxtries) { res = ast_app_getdata(chan, errmsg, user, sizeof(user) - 1, 0); + } } LOCAL_USER_REMOVE(u); ! if (!res) ! res = ast_safe_sleep(chan, 500); ! ! /* Play vm-goodbye and return based upon callbackmode and login_state */ ! if (!callbackmode) ! return -1; ! if (set_vars && login_state==1) { ! if (set_vars==1) { ! pbx_builtin_setvar_helper(chan, "AGENTNUMBER", user); ! pbx_builtin_setvar_helper(chan, "AGENTPASS", pass); ! pbx_builtin_setvar_helper(chan, "AGENTEXTEN", exten); ! } ! if (set_vars==2) { ! pbx_builtin_setvar_helper(NULL, "AGENTNUMBER", user); ! pbx_builtin_setvar_helper(NULL, "AGENTPASS", pass); ! pbx_builtin_setvar_helper(NULL, "AGENTEXTEN", exten); ! } ! } ! if (play_goodbye==2 || (play_goodbye==1 && login_state==0) || (hangup_logoff==2 && login_state==2)) { ! if (!res) ! res = ast_safe_sleep(chan, 1000); ! res = ast_streamfile(chan, "vm-goodbye", chan->language); ! if (!res) ! res = ast_waitstream(chan, ""); ! if (!res) ! res = ast_safe_sleep(chan, 1000); ! } ! if (hangup_call==1 || (hangup_logoff>0 && login_state==2) || (hangup_call==2 && login_state==0)) { ! return -1; ! } ! return 0; } static int login_exec(struct ast_channel *chan, void *data)