[Asterisk-cvs] asterisk/channels chan_agent.c,1.140,1.141

kpfleming at lists.digium.com kpfleming at lists.digium.com
Tue Jul 5 21:20:22 CDT 2005


Update of /usr/cvsroot/asterisk/channels
In directory localhost.localdomain:/tmp/cvs-serv2928/channels

Modified Files:
	chan_agent.c 
Log Message:
remember CallerID in AgentCallbackLogin, so it can be used at logoff time
use stored CallerID when auto-logoff occurs to clear AGENTBYCALLERID variable (bug #4616)
persist stored CallerID into/out of astdb


Index: chan_agent.c
===================================================================
RCS file: /usr/cvsroot/asterisk/channels/chan_agent.c,v
retrieving revision 1.140
retrieving revision 1.141
diff -u -d -r1.140 -r1.141
--- chan_agent.c	24 Jun 2005 02:15:04 -0000	1.140
+++ chan_agent.c	6 Jul 2005 01:29:15 -0000	1.141
@@ -162,7 +162,8 @@
 	volatile pthread_t owning_app;		/* Owning application thread id */
 	volatile int app_sleep_cond;		/* Sleep condition for the login app */
 	struct ast_channel *owner;		/* Agent */
-	char loginchan[80];
+	char loginchan[80];			/* channel they logged in from */
+	char logincallerid[80];			/* Caller ID they had when they logged in */
 	struct ast_channel *chan;		/* Channel we use */
 	struct agent_pvt *next;			/* Agent */
 } *agents = NULL;
@@ -650,6 +651,19 @@
 	return res;
 }
 
+/* store/clear the global variable that stores agentid based on the callerid */
+static void set_agentbycallerid(const struct agent_pvt *agent)
+{
+	char buf[AST_MAX_BUF];
+
+	/* if there is no Caller ID, nothing to do */
+	if (!agent->logincallerid[0])
+		return;
+
+	snprintf(buf, sizeof(buf), "%s_%s",GETAGENTBYCALLERID, agent->logincallerid);
+	pbx_builtin_setvar_helper(NULL, buf, ast_strlen_zero(agent->loginchan) ? NULL : agent->agent);
+}
+
 static int agent_hangup(struct ast_channel *ast)
 {
 	struct agent_pvt *p = ast->tech_pvt;
@@ -715,6 +729,8 @@
 				snprintf(agent, sizeof(agent), "Agent/%s", p->agent);
 				ast_queue_log("NONE", ast->uniqueid, agent, "AGENTCALLBACKLOGOFF", "%s|%ld|%s", p->loginchan, logintime, "Autologoff");
 				p->loginchan[0] = '\0';
+				set_agentbycallerid(p);
+				p->logincallerid[0] = '\0';
 			}
 		} else if (p->dead) {
 			ast_mutex_lock(&p->chan->lock);
@@ -1404,6 +1420,8 @@
 				p->agent, p->loginchan, logintime);
 			ast_queue_log("NONE", "NONE", agent, "AGENTCALLBACKLOGOFF", "%s|%ld|%s", p->loginchan, logintime, "CommandLogoff");
 			p->loginchan[0] = '\0';
+			set_agentbycallerid(p);
+			p->logincallerid[0] = '\0';
 			ast_cli(fd, "Logging out %s\n", agent);
 			ast_device_state_changed("Agent/%s", p->agent);
 			if (persistent_agents)
@@ -1729,29 +1747,29 @@
 								if (context && !ast_strlen_zero(context) && !ast_strlen_zero(tmpchan))
 									snprintf(p->loginchan, sizeof(p->loginchan), "%s@%s", tmpchan, context);
 								else {
-	                                                                strncpy(last_loginchan, p->loginchan, sizeof(last_loginchan) - 1);
-									strncpy(p->loginchan, tmpchan, sizeof(p->loginchan) - 1);
+	                                                                ast_copy_string(last_loginchan, p->loginchan, sizeof(last_loginchan));
+									ast_copy_string(p->loginchan, tmpchan, sizeof(p->loginchan));
 								}
+								p->acknowledged = 0;
 								if (ast_strlen_zero(p->loginchan)) {
 									login_state = 2;
 									filename = "agent-loggedoff";
+									set_agentbycallerid(p);
+								} else {
+									if (chan->cid.cid_num) {
+										ast_copy_string(p->logincallerid, chan->cid.cid_num, sizeof(p->logincallerid));
+										set_agentbycallerid(p);
+									} else
+										p->logincallerid[0] = '\0';
 								}
-								p->acknowledged = 0;
-								/* store/clear the global variable that stores agentid based on the callerid */
-								if (chan->cid.cid_num) {
-									char agentvar[AST_MAX_BUF];
-									snprintf(agentvar, sizeof(agentvar), "%s_%s",GETAGENTBYCALLERID, chan->cid.cid_num);
-									if (ast_strlen_zero(p->loginchan))
-										pbx_builtin_setvar_helper(NULL, agentvar, NULL);
-									else
-										pbx_builtin_setvar_helper(NULL, agentvar, p->agent);
-								}
+
 								if(update_cdr && chan->cdr)
 									snprintf(chan->cdr->channel, sizeof(chan->cdr->channel), "Agent/%s", p->agent);
 
 							}
 						} else {
 							p->loginchan[0] = '\0';
+							p->logincallerid[0] = '\0';
 							p->acknowledged = 0;
 						}
 						ast_mutex_unlock(&p->lock);
@@ -2048,13 +2066,15 @@
 static void dump_agents(void)
 {
 	struct agent_pvt *cur_agent = NULL;
+	char buf[256];
 
 	for (cur_agent = agents; cur_agent; cur_agent = cur_agent->next) {
 		if (cur_agent->chan)
 			continue;
 
 		if (!ast_strlen_zero(cur_agent->loginchan)) {
-			if (ast_db_put(pa_family, cur_agent->agent, cur_agent->loginchan))
+			snprintf(buf, sizeof(buf), "%s;%s", cur_agent->loginchan, cur_agent->logincallerid);
+			if (ast_db_put(pa_family, cur_agent->agent, buf))
 				ast_log(LOG_WARNING, "failed to create persistent entry!\n");
 			else if (option_debug)
 				ast_log(LOG_DEBUG, "Saved Agent: %s on %s\n", cur_agent->agent, cur_agent->loginchan);
@@ -2072,7 +2092,10 @@
 	struct ast_db_entry *db_tree;
 	struct ast_db_entry *entry;
 	struct agent_pvt *cur_agent;
-	char agent_data[80];
+	char agent_data[256];
+	char *parse;
+	char *agent_chan;
+	char *agent_callerid;
 
 	db_tree = ast_db_gettree(pa_family, NULL);
 
@@ -2095,7 +2118,14 @@
 		if (!ast_db_get(pa_family, agent_num, agent_data, sizeof(agent_data)-1)) {
 			if (option_debug)
 				ast_log(LOG_DEBUG, "Reload Agent: %s on %s\n", cur_agent->agent, agent_data);
-			strncpy(cur_agent->loginchan, agent_data, sizeof(cur_agent->loginchan)-1);
+			parse = agent_data;
+			agent_chan = strsep(&parse, ";");
+			agent_callerid = strsep(&parse, ";");
+			ast_copy_string(cur_agent->loginchan, agent_chan, sizeof(cur_agent->loginchan));
+			if (agent_callerid)
+				ast_copy_string(cur_agent->logincallerid, agent_callerid, sizeof(cur_agent->logincallerid));
+			else
+				cur_agent->logincallerid[0] = '\0';
 			if (cur_agent->loginstart == 0)
 				time(&cur_agent->loginstart);
 			ast_device_state_changed("Agent/%s", cur_agent->agent);	




More information about the svn-commits mailing list