[asterisk-commits] branch oej/astum r8679 - in /team/oej/astum: ./ apps/ cdr/ channels/ configs/...

asterisk-commits at lists.digium.com asterisk-commits at lists.digium.com
Wed Jan 25 12:41:57 MST 2006


Author: oej
Date: Wed Jan 25 13:41:47 2006
New Revision: 8679

URL: http://svn.digium.com/view/asterisk?rev=8679&view=rev
Log:
Merged revisions 8517,8523-8524,8531,8538-8539,8548,8554,8560-8561,8563,8571-8572,8574,8582,8587,8589-8597,8599,8609-8610,8618,8620,8633,8642-8643,8654,8664-8665,8667,8676,8678 via svnmerge from 
https://origsvn.digium.com/svn/asterisk/trunk

................
r8517 | oej | 2006-01-24 11:36:45 +0100 (Tue, 24 Jan 2006) | 2 lines

Whitespace change, extra <tab> added from my tab storage.

................
r8523 | oej | 2006-01-24 12:42:09 +0100 (Tue, 24 Jan 2006) | 2 lines

Declaring conn and result static to avoid collission with realtime driver (issue 6336, pressureman)

................
r8524 | oej | 2006-01-24 12:46:29 +0100 (Tue, 24 Jan 2006) | 3 lines

- Adding whitespace that I found unused outside 
- Adding "if (option_debug)" before outputting to DEBUG channel

................
r8531 | oej | 2006-01-24 13:48:44 +0100 (Tue, 24 Jan 2006) | 2 lines

- Report SIP reload in manager (issue 5742 with small changes)

................
r8538 | oej | 2006-01-24 14:21:13 +0100 (Tue, 24 Jan 2006) | 2 lines

Importing rev #8537 from 1.2, never send response to ACK (issue #6308)

................
r8539 | oej | 2006-01-24 14:53:45 +0100 (Tue, 24 Jan 2006) | 2 lines

Issue #6323, FreeBSD compatibility with compilation of func_odbc.c (reported by nulbyte)

................
r8548 | oej | 2006-01-24 18:47:41 +0100 (Tue, 24 Jan 2006) | 2 lines

Reverting change in revision 8539 - fixed wrong problem. Sorry.

................
r8554 | oej | 2006-01-24 19:15:20 +0100 (Tue, 24 Jan 2006) | 2 lines

Make it clear that caller ID in sip.conf is used only on incoming calls (inspired by bug #6183)

................
r8560 | oej | 2006-01-24 20:08:44 +0100 (Tue, 24 Jan 2006) | 2 lines

Issue #6093: Match realtime non-dynamic peers by IP. (siacali).

................
r8561 | oej | 2006-01-24 20:19:20 +0100 (Tue, 24 Jan 2006) | 2 lines

Issue 6114: Don't hangup on bye/also if there's no channel. (gst)

................
r8563 | oej | 2006-01-24 20:29:32 +0100 (Tue, 24 Jan 2006) | 2 lines

Blocking fix from 1.2 from being applied again. 

................
r8571 | russell | 2006-01-24 21:20:05 +0100 (Tue, 24 Jan 2006) | 2 lines

convert ast_channel list to use linked list macros (issue #6338)

................
r8572 | russell | 2006-01-24 21:27:09 +0100 (Tue, 24 Jan 2006) | 2 lines

store the list of 'atexit' functions using linked list macros (issue #6329)

................
r8574 | oej | 2006-01-24 21:41:08 +0100 (Tue, 24 Jan 2006) | 2 lines

Don't reset scheduled ID until we actually end the scheduled event.

................
r8582 | mattf | 2006-01-24 22:45:42 +0100 (Tue, 24 Jan 2006) | 2 lines

Updates from royk to safe_asterisk (#5207) Thanks!

................
r8587 | mattf | 2006-01-24 23:06:37 +0100 (Tue, 24 Jan 2006) | 2 lines

Make sure safe_asterisk retains previous script defaults

................
r8589 | kpfleming | 2006-01-24 23:33:58 +0100 (Tue, 24 Jan 2006) | 1 line


................
r8590 | kpfleming | 2006-01-24 23:34:06 +0100 (Tue, 24 Jan 2006) | 1 line


................
r8591 | kpfleming | 2006-01-24 23:38:17 +0100 (Tue, 24 Jan 2006) | 10 lines

Merged revisions 8588 via svnmerge from 
https://origsvn.digium.com/svn/asterisk/branches/1.2

........
r8588 | kpfleming | 2006-01-24 16:32:09 -0600 (Tue, 24 Jan 2006) | 2 lines

ensure that channel cannot become zombie after we check but before we try to start indications

........

................
r8592 | kpfleming | 2006-01-24 23:40:20 +0100 (Tue, 24 Jan 2006) | 1 line


................
r8593 | kpfleming | 2006-01-24 23:40:57 +0100 (Tue, 24 Jan 2006) | 1 line


................
r8594 | kpfleming | 2006-01-24 23:41:45 +0100 (Tue, 24 Jan 2006) | 1 line


................
r8595 | kpfleming | 2006-01-24 23:42:43 +0100 (Tue, 24 Jan 2006) | 10 lines

Merged revisions 8173 via svnmerge from 
https://origsvn.digium.com/svn/asterisk/branches/1.2

........
r8173 | russell | 2006-01-17 20:49:21 -0600 (Tue, 17 Jan 2006) | 2 lines

remove ChangeLog from the 1.2 branch.  It will only be present in the tags.

........

................
r8596 | kpfleming | 2006-01-24 23:43:30 +0100 (Tue, 24 Jan 2006) | 1 line


................
r8597 | kpfleming | 2006-01-24 23:43:57 +0100 (Tue, 24 Jan 2006) | 2 lines

clean up remaining already-merged revisions

................
r8599 | kpfleming | 2006-01-24 23:45:41 +0100 (Tue, 24 Jan 2006) | 2 lines

remove extraneous characters from property

................
r8609 | kpfleming | 2006-01-25 02:52:58 +0100 (Wed, 25 Jan 2006) | 10 lines

Merged revisions 8608 via svnmerge from 
https://origsvn.digium.com/svn/asterisk/branches/1.2

........
r8608 | kpfleming | 2006-01-24 19:50:52 -0600 (Tue, 24 Jan 2006) | 2 lines

ensure hangup cause code is handled properly when channel does not return a frame (issue #6346)

........

................
r8610 | kpfleming | 2006-01-25 02:53:15 +0100 (Wed, 25 Jan 2006) | 1 line


................
r8618 | russell | 2006-01-25 06:37:29 +0100 (Wed, 25 Jan 2006) | 3 lines

don't leak almost 200 bytes for each new channel and store the active
channel list using the linked list macros (issue #6330)

................
r8620 | russell | 2006-01-25 06:39:25 +0100 (Wed, 25 Jan 2006) | 1 line


................
r8633 | oej | 2006-01-25 10:50:28 +0100 (Wed, 25 Jan 2006) | 2 lines

Issue #6349 - patch by markster, imported from 1.2

................
r8642 | oej | 2006-01-25 13:01:07 +0100 (Wed, 25 Jan 2006) | 3 lines

>From now on, apply maxexpiry and minexpiry to all subscriptions. Thanks to fourcheeze in the IRC channel
for pointing this out.

................
r8643 | oej | 2006-01-25 13:11:30 +0100 (Wed, 25 Jan 2006) | 3 lines

- Remove unused option to transmit_state_notify
- Allow for expiry=0 in subscription requests that only wants *one* update and that's it.

................
r8654 | kpfleming | 2006-01-25 15:52:43 +0100 (Wed, 25 Jan 2006) | 3 lines

don't queue a congestion frame on a channel that will be immediately hung up anyway
clean up/organize code block

................
r8664 | russell | 2006-01-25 19:12:55 +0100 (Wed, 25 Jan 2006) | 2 lines

store agent_pvt list using linked list macros (issue #6342)

................
r8665 | russell | 2006-01-25 19:24:32 +0100 (Wed, 25 Jan 2006) | 3 lines

store feature_pvt list using linked list macros
(issue #6351, with additional changes to prevent a memory leak in unload_module)

................
r8667 | russell | 2006-01-25 19:41:12 +0100 (Wed, 25 Jan 2006) | 1 line


................
r8676 | russell | 2006-01-25 20:06:37 +0100 (Wed, 25 Jan 2006) | 2 lines

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

................
r8678 | russell | 2006-01-25 20:16:14 +0100 (Wed, 25 Jan 2006) | 11 lines

Merged revisions 8677 via svnmerge from 
https://origsvn.digium.com/svn/asterisk/branches/1.2

........
r8677 | russell | 2006-01-25 14:14:43 -0500 (Wed, 25 Jan 2006) | 3 lines

don't call ast_update_realtime with uninitialized variables if we get a
registration with an expirey of 0 seconds (issue #6173)

........

................

Removed:
    team/oej/astum/ChangeLog
Modified:
    team/oej/astum/   (props changed)
    team/oej/astum/apps/app_dial.c
    team/oej/astum/asterisk.c
    team/oej/astum/cdr/cdr_pgsql.c
    team/oej/astum/channel.c
    team/oej/astum/channels/chan_agent.c
    team/oej/astum/channels/chan_features.c
    team/oej/astum/channels/chan_iax2.c
    team/oej/astum/channels/chan_sip.c
    team/oej/astum/configs/sip.conf.sample
    team/oej/astum/contrib/scripts/safe_asterisk
    team/oej/astum/include/asterisk/channel.h
    team/oej/astum/rtp.c
    team/oej/astum/utils/astman.c

Propchange: team/oej/astum/
------------------------------------------------------------------------------
--- svnmerge-blocked (original)
+++ svnmerge-blocked Wed Jan 25 13:41:47 2006
@@ -1,1 +1,1 @@
-/branches/1.2:7490,7497,7517,7529,7546,7550,7552,7557,7580,7586,7595,7605,7641,7663,7706,7738,7771,7792,7812,7870-7871,7898-7900,7915,7960,7965,7970,7976,8047,8112,8394,8412,8418,8445
+/branches/1.2:7490,7497,7517,7529,7546,7550,7552,7557,7580,7586,7595,7605,7641,7663,7706,7738,7771,7792,7812,7870-7871,7898-7900,7915,7960,7965,7970,7976,8047,8112,8124,8134,8394,8412,8414,8418,8429,8433,8445,8562,8573,8600,8619,8666

Propchange: team/oej/astum/
------------------------------------------------------------------------------
--- svnmerge-integrated (original)
+++ svnmerge-integrated Wed Jan 25 13:41:47 2006
@@ -1,1 +1,1 @@
-/trunk:1-8514
+/trunk:1-8678

Modified: team/oej/astum/apps/app_dial.c
URL: http://svn.digium.com/view/asterisk/team/oej/astum/apps/app_dial.c?rev=8679&r1=8678&r2=8679&view=diff
==============================================================================
--- team/oej/astum/apps/app_dial.c (original)
+++ team/oej/astum/apps/app_dial.c Wed Jan 25 13:41:47 2006
@@ -657,6 +657,7 @@
 					ast_hangup(o->chan);
 					o->chan = NULL;
 					ast_clear_flag(o, DIAL_STILLGOING);
+					HANDLE_CAUSE(in->hangupcause, in);
 				}
 			}
 			o = o->next;

Modified: team/oej/astum/asterisk.c
URL: http://svn.digium.com/view/asterisk/team/oej/astum/asterisk.c?rev=8679&r1=8678&r2=8679&view=diff
==============================================================================
--- team/oej/astum/asterisk.c (original)
+++ team/oej/astum/asterisk.c Wed Jan 25 13:41:47 2006
@@ -167,12 +167,12 @@
 	pthread_t t;			/*!< Thread of handler */
 };
 
-static struct ast_atexit {
+struct ast_atexit {
 	void (*func)(void);
-	struct ast_atexit *next;
-} *atexits = NULL;
-
-AST_MUTEX_DEFINE_STATIC(atexitslock);
+	AST_LIST_ENTRY(ast_atexit) list;
+};
+
+static AST_LIST_HEAD_STATIC(atexits, ast_atexit);
 
 time_t ast_startuptime;
 time_t ast_lastreloadtime;
@@ -355,35 +355,29 @@
 	struct ast_atexit *ae;
 	ast_unregister_atexit(func);
 	ae = malloc(sizeof(struct ast_atexit));
-	ast_mutex_lock(&atexitslock);
+	AST_LIST_LOCK(&atexits);
 	if (ae) {
 		memset(ae, 0, sizeof(struct ast_atexit));
-		ae->next = atexits;
+		AST_LIST_INSERT_HEAD(&atexits, ae, list);
 		ae->func = func;
-		atexits = ae;
 		res = 0;
 	}
-	ast_mutex_unlock(&atexitslock);
+	AST_LIST_UNLOCK(&atexits);
 	return res;
 }
 
 void ast_unregister_atexit(void (*func)(void))
 {
-	struct ast_atexit *ae, *prev = NULL;
-	ast_mutex_lock(&atexitslock);
-	ae = atexits;
-	while(ae) {
+	struct ast_atexit *ae;
+	AST_LIST_LOCK(&atexits);
+	AST_LIST_TRAVERSE_SAFE_BEGIN(&atexits, ae, list) {
 		if (ae->func == func) {
-			if (prev)
-				prev->next = ae->next;
-			else
-				atexits = ae->next;
+			AST_LIST_REMOVE_CURRENT(&atexits, list);
 			break;
 		}
-		prev = ae;
-		ae = ae->next;
-	}
-	ast_mutex_unlock(&atexitslock);
+	}
+	AST_LIST_TRAVERSE_SAFE_END
+	AST_LIST_UNLOCK(&atexits);
 }
 
 static int fdprint(int fd, const char *s)
@@ -806,14 +800,12 @@
 static void ast_run_atexits(void)
 {
 	struct ast_atexit *ae;
-	ast_mutex_lock(&atexitslock);
-	ae = atexits;
-	while(ae) {
+	AST_LIST_LOCK(&atexits);
+	AST_LIST_TRAVERSE(&atexits, ae, list) {
 		if (ae->func) 
 			ae->func();
-		ae = ae->next;
-	}
-	ast_mutex_unlock(&atexitslock);
+	}
+	AST_LIST_UNLOCK(&atexits);
 }
 
 static void quit_handler(int num, int nice, int safeshutdown, int restart)

Modified: team/oej/astum/cdr/cdr_pgsql.c
URL: http://svn.digium.com/view/asterisk/team/oej/astum/cdr/cdr_pgsql.c?rev=8679&r1=8678&r2=8679&view=diff
==============================================================================
--- team/oej/astum/cdr/cdr_pgsql.c (original)
+++ team/oej/astum/cdr/cdr_pgsql.c Wed Jan 25 13:41:47 2006
@@ -1,7 +1,7 @@
 /*
  * Asterisk -- An open source telephony toolkit.
  *
- * Copyright (C) 2003 - 2005
+ * Copyright (C) 2003 - 2006
  *
  * Matthew D. Hardeman <mhardemn at papersoft.com> 
  * Adapted from the MySQL CDR logger originally by James Sharp 
@@ -64,8 +64,8 @@
 
 AST_MUTEX_DEFINE_STATIC(pgsql_lock);
 
-PGconn		*conn;
-PGresult	*result;
+static PGconn	*conn;
+static PGresult	*result;
 
 static int pgsql_log(struct ast_cdr *cdr)
 {
@@ -118,7 +118,8 @@
 			return -1;
 		}
 
-		ast_log(LOG_DEBUG,"cdr_pgsql: inserting a CDR record.\n");
+		if (option_debug > 1)
+			ast_log(LOG_DEBUG, "cdr_pgsql: inserting a CDR record.\n");
 
 		snprintf(sqlcmd,sizeof(sqlcmd),"INSERT INTO %s (calldate,clid,src,dst,dcontext,channel,dstchannel,"
 				 "lastapp,lastdata,duration,billsec,disposition,amaflags,accountcode,uniqueid,userfield) VALUES"
@@ -126,7 +127,8 @@
 				 table,timestr,clid,cdr->src, cdr->dst, dcontext,channel, dstchannel, lastapp, lastdata,
 				 cdr->duration,cdr->billsec,ast_cdr_disp2str(cdr->disposition),cdr->amaflags, cdr->accountcode, uniqueid, userfield);
 		
-		ast_log(LOG_DEBUG,"cdr_pgsql: SQL command executed:  %s\n",sqlcmd);
+		if (option_debug > 2)
+			ast_log(LOG_DEBUG, "cdr_pgsql: SQL command executed:  %s\n",sqlcmd);
 		
 		/* Test to be sure we're still connected... */
 		/* If we're connected, and connection is working, good. */
@@ -280,18 +282,21 @@
 		return -1;
 	}
 
-	ast_log(LOG_DEBUG,"cdr_pgsql: got hostname of %s\n",pghostname);
-	ast_log(LOG_DEBUG,"cdr_pgsql: got port of %s\n",pgdbport);
-	if (pgdbsock)
-		ast_log(LOG_DEBUG,"cdr_pgsql: got sock file of %s\n",pgdbsock);
-	ast_log(LOG_DEBUG,"cdr_pgsql: got user of %s\n",pgdbuser);
-	ast_log(LOG_DEBUG,"cdr_pgsql: got dbname of %s\n",pgdbname);
-	ast_log(LOG_DEBUG,"cdr_pgsql: got password of %s\n",pgpassword);
-	ast_log(LOG_DEBUG,"cdr_pgsql: got sql table name of %s\n",table);
+	if (option_debug) {
+		ast_log(LOG_DEBUG, "cdr_pgsql: got hostname of %s\n", pghostname);
+		ast_log(LOG_DEBUG, "cdr_pgsql: got port of %s\n", pgdbport);
+		if (pgdbsock)
+			ast_log(LOG_DEBUG, "cdr_pgsql: got sock file of %s\n", pgdbsock);
+		ast_log(LOG_DEBUG, "cdr_pgsql: got user of %s\n", pgdbuser);
+		ast_log(LOG_DEBUG, "cdr_pgsql: got dbname of %s\n", pgdbname);
+		ast_log(LOG_DEBUG, "cdr_pgsql: got password of %s\n", pgpassword);
+		ast_log(LOG_DEBUG, "cdr_pgsql: got sql table name of %s\n", table);
+	}
 	
 	conn = PQsetdbLogin(pghostname, pgdbport, NULL, NULL, pgdbname, pgdbuser, pgpassword);
 	if (PQstatus(conn) != CONNECTION_BAD) {
-		ast_log(LOG_DEBUG,"Successfully connected to PostgreSQL database.\n");
+		if (option_debug)
+			ast_log(LOG_DEBUG, "Successfully connected to PostgreSQL database.\n");
 		connected = 1;
 	} else {
                 pgerror = PQerrorMessage(conn);

Modified: team/oej/astum/channel.c
URL: http://svn.digium.com/view/asterisk/team/oej/astum/channel.c?rev=8679&r1=8678&r2=8679&view=diff
==============================================================================
--- team/oej/astum/channel.c (original)
+++ team/oej/astum/channel.c Wed Jan 25 13:41:47 2006
@@ -108,11 +108,9 @@
 /*! the list of registered channel types */
 static AST_LIST_HEAD_NOLOCK_STATIC(backends, chanlist);
 
-/*! the list of channels we have */
-static struct ast_channel *channels = NULL;
-
-/*! Protect the channel list, both backends and channels. */
-AST_MUTEX_DEFINE_STATIC(chlock);
+/*! the list of channels we have. Note that the lock for this list is used for
+    both the channels list and the backends list.  */
+static AST_LIST_HEAD_STATIC(channels, ast_channel);
 
 /*! map AST_CAUSE's to readable string representations */
 const struct ast_cause {
@@ -174,7 +172,7 @@
 
 	ast_cli(fd, FORMAT, "Type", "Description",       "Devicestate", "Indications", "Transfer");
 	ast_cli(fd, FORMAT, "----------", "-----------", "-----------", "-----------", "--------");
-	if (ast_mutex_lock(&chlock)) {
+	if (AST_LIST_LOCK(&channels)) {
 		ast_log(LOG_WARNING, "Unable to lock channel list\n");
 		return -1;
 	}
@@ -185,7 +183,7 @@
 			(cl->tech->transfer) ? "yes" : "no");
 		count_chan++;
 	}
-	ast_mutex_unlock(&chlock);
+	AST_LIST_UNLOCK(&channels);
 	ast_cli(fd, "----------\n%d channel drivers registered.\n", count_chan);
 	return RESULT_SUCCESS;
 
@@ -200,7 +198,7 @@
 	if (argc != 3)
 		return RESULT_SHOWUSAGE;
 	
-	if (ast_mutex_lock(&chlock)) {
+	if (AST_LIST_LOCK(&channels)) {
 		ast_log(LOG_WARNING, "Unable to lock channel list\n");
 		return RESULT_FAILURE;
 	}
@@ -214,7 +212,7 @@
 
 	if (!cl) {
 		ast_cli(fd, "\n%s is not a registered channel driver.\n", argv[2]);
-		ast_mutex_unlock(&chlock);
+		AST_LIST_UNLOCK(&channels);
 		return RESULT_FAILURE;
 	} 
 
@@ -240,7 +238,7 @@
 		
 	);
 
-	ast_mutex_unlock(&chlock);
+	AST_LIST_UNLOCK(&channels);
 	return RESULT_SUCCESS;
 }
 
@@ -317,10 +315,10 @@
 	struct ast_channel *c;
 	shutting_down = 1;
 	if (hangup) {
-		ast_mutex_lock(&chlock);
-		for (c = channels; c; c = c->next)
+		AST_LIST_LOCK(&channels);
+		AST_LIST_TRAVERSE(&channels, c, list)
 			ast_softhangup(c, AST_SOFTHANGUP_SHUTDOWN);
-		ast_mutex_unlock(&chlock);
+		AST_LIST_UNLOCK(&channels);
 	}
 }
 
@@ -329,10 +327,10 @@
 {
 	struct ast_channel *c;
 	int cnt = 0;
-	ast_mutex_lock(&chlock);
-	for (c = channels; c; c = c->next)
+	AST_LIST_LOCK(&channels);
+	AST_LIST_TRAVERSE(&channels, c, list)
 		cnt++;
-	ast_mutex_unlock(&chlock);
+	AST_LIST_UNLOCK(&channels);
 	return cnt;
 }
 
@@ -393,12 +391,12 @@
 {
 	struct chanlist *chan;
 
-	ast_mutex_lock(&chlock);
+	AST_LIST_LOCK(&channels);
 
 	AST_LIST_TRAVERSE(&backends, chan, list) {
 		if (!strcasecmp(tech->type, chan->tech->type)) {
 			ast_log(LOG_WARNING, "Already have a handler for type '%s'\n", tech->type);
-			ast_mutex_unlock(&chlock);
+			AST_LIST_UNLOCK(&channels);
 			return -1;
 		}
 	}
@@ -406,7 +404,7 @@
 	chan = malloc(sizeof(*chan));
 	if (!chan) {
 		ast_log(LOG_WARNING, "Out of memory\n");
-		ast_mutex_unlock(&chlock);
+		AST_LIST_UNLOCK(&channels);
 		return -1;
 	}
 	chan->tech = tech;
@@ -419,7 +417,7 @@
 		ast_verbose(VERBOSE_PREFIX_2 "Registered channel type '%s' (%s)\n", chan->tech->type,
 			    chan->tech->description);
 
-	ast_mutex_unlock(&chlock);
+	AST_LIST_UNLOCK(&channels);
 	return 0;
 }
 
@@ -430,7 +428,7 @@
 	if (option_debug)
 		ast_log(LOG_DEBUG, "Unregistering channel type '%s'\n", tech->type);
 
-	ast_mutex_lock(&chlock);
+	AST_LIST_LOCK(&channels);
 
 	AST_LIST_TRAVERSE_SAFE_BEGIN(&backends, chan, list) {
 		if (chan->tech == tech) {
@@ -443,7 +441,7 @@
 	}
 	AST_LIST_TRAVERSE_SAFE_END
 
-	ast_mutex_unlock(&chlock);
+	AST_LIST_UNLOCK(&channels);
 }
 
 const struct ast_channel_tech *ast_get_channel_tech(const char *name)
@@ -451,7 +449,7 @@
 	struct chanlist *chanls;
 	const struct ast_channel_tech *ret = NULL;
 
-	if (ast_mutex_lock(&chlock)) {
+	if (AST_LIST_LOCK(&channels)) {
 		ast_log(LOG_WARNING, "Unable to lock channel tech list\n");
 		return NULL;
 	}
@@ -463,7 +461,7 @@
 		}
 	}
 
-	ast_mutex_unlock(&chlock);
+	AST_LIST_UNLOCK(&channels);
 	
 	return ret;
 }
@@ -664,11 +662,9 @@
 
 	tmp->tech = &null_tech;
 
-	ast_mutex_lock(&chlock);
-	tmp->next = channels;
-	channels = tmp;
-
-	ast_mutex_unlock(&chlock);
+	AST_LIST_LOCK(&channels);
+	AST_LIST_INSERT_HEAD(&channels, tmp, list);
+	AST_LIST_UNLOCK(&channels);
 	return tmp;
 }
 
@@ -801,8 +797,8 @@
 	struct ast_channel *c;
 
 	for (retries = 0; retries < 10; retries++) {
-		ast_mutex_lock(&chlock);
-		for (c = channels; c; c = c->next) {
+		AST_LIST_LOCK(&channels);
+		AST_LIST_TRAVERSE(&channels, c, list) {
 			if (!prev) {
 				/* want head of list */
 				if (!name && !exten)
@@ -831,7 +827,7 @@
 						break;
 				}
 			} else if (c == prev) { /* found, return c->next */
-				c = c->next;
+				c = AST_LIST_NEXT(c, list);
 				break;
 			}
 		}
@@ -840,7 +836,7 @@
 		/* this is slightly unsafe, as we _should_ hold the lock to access c->name */
 		if (!done && c)
 			ast_log(LOG_DEBUG, "Avoiding %s for '%s'\n", msg, c->name);
-		ast_mutex_unlock(&chlock);
+		AST_LIST_UNLOCK(&channels);
 		if (done)
 			return c;
 		usleep(1);
@@ -929,7 +925,6 @@
 /*! \brief Free a channel structure */
 void ast_channel_free(struct ast_channel *chan)
 {
-	struct ast_channel *last=NULL, *cur;
 	int fd;
 	struct ast_var_t *vardata;
 	struct ast_frame *f, *fp;
@@ -938,25 +933,12 @@
 	
 	headp=&chan->varshead;
 	
-	ast_mutex_lock(&chlock);
-	for (cur = channels; cur; cur = cur->next) {
-		if (cur == chan) {
-			if (last)
-				last->next = cur->next;
-			else
-				channels = cur->next;
-			break;
-		}
-		last = cur;
-	}
-	if (!cur)
-		ast_log(LOG_WARNING, "Unable to find channel in list\n");
-	else {
-		/* Lock and unlock the channel just to be sure nobody
-		   has it locked still */
-		ast_mutex_lock(&cur->lock);
-		ast_mutex_unlock(&cur->lock);
-	}
+	AST_LIST_LOCK(&channels);
+	AST_LIST_REMOVE(&channels, chan, list);
+	/* Lock and unlock the channel just to be sure nobody
+	   has it locked still */
+	ast_mutex_lock(&chan->lock);
+	ast_mutex_unlock(&chan->lock);
 	if (chan->tech_pvt) {
 		ast_log(LOG_WARNING, "Channel '%s' may not have been hung up properly\n", chan->name);
 		free(chan->tech_pvt);
@@ -1007,7 +989,7 @@
 		ast_var_delete(vardata);
 
 	free(chan);
-	ast_mutex_unlock(&chlock);
+	AST_LIST_UNLOCK(&channels);
 
 	ast_device_state_changed_literal(name);
 }
@@ -2068,10 +2050,12 @@
 {
 	int res = -1;
 
+	ast_mutex_lock(&chan->lock);
 	/* Stop if we're a zombie or need a soft hangup */
-	if (ast_test_flag(chan, AST_FLAG_ZOMBIE) || ast_check_hangup(chan)) 
+	if (ast_test_flag(chan, AST_FLAG_ZOMBIE) || ast_check_hangup(chan)) {
+		ast_mutex_unlock(&chan->lock);
 		return -1;
-	ast_mutex_lock(&chan->lock);
+	}
 	if (chan->tech->indicate)
 		res = chan->tech->indicate(chan, condition);
 	ast_mutex_unlock(&chan->lock);
@@ -2564,7 +2548,7 @@
 		cause = &foo;
 	*cause = AST_CAUSE_NOTDEFINED;
 
-	if (ast_mutex_lock(&chlock)) {
+	if (AST_LIST_LOCK(&channels)) {
 		ast_log(LOG_WARNING, "Unable to lock channel list\n");
 		return NULL;
 	}
@@ -2578,10 +2562,10 @@
 		res = ast_translator_best_choice(&fmt, &capabilities);
 		if (res < 0) {
 			ast_log(LOG_WARNING, "No translator path exists for channel type %s (native %d) to %d\n", type, chan->tech->capabilities, format);
-			ast_mutex_unlock(&chlock);
+			AST_LIST_UNLOCK(&channels);
 			return NULL;
 		}
-		ast_mutex_unlock(&chlock);
+		AST_LIST_UNLOCK(&channels);
 		if (!chan->tech->requester)
 			return NULL;
 		
@@ -2605,7 +2589,7 @@
 
 	ast_log(LOG_WARNING, "No channel type registered for '%s'\n", type);
 	*cause = AST_CAUSE_NOSUCHDRIVER;
-	ast_mutex_unlock(&chlock);
+	AST_LIST_UNLOCK(&channels);
 
 	return NULL;
 }
@@ -3314,11 +3298,14 @@
 			res = AST_BRIDGE_RETRY;
 			break;
 		}
-		to = ast_tvdiff_ms(bridge_end, ast_tvnow());
-		if (to <= 0) {
-			res = AST_BRIDGE_RETRY;
-			break;
-		}
+		if (bridge_end.tv_sec) {
+			to = ast_tvdiff_ms(bridge_end, ast_tvnow());
+			if (to <= 0) {
+				res = AST_BRIDGE_RETRY;
+				break;
+			}
+		} else
+			to = -1;
 		who = ast_waitfor_n(cs, 2, &to);
 		if (!who) {
 			ast_log(LOG_DEBUG, "Nobody there, continuing...\n"); 
@@ -4125,3 +4112,19 @@
 
 	free(state);
 }
+
+
+/*! \ brief Convert channel reloadreason (ENUM) to text string for manager event */
+const char *channelreloadreason2txt(enum channelreloadreason reason) {
+	switch (reason) {
+	case CHANNEL_MODULE_LOAD:	return "LOAD (Channel module load)";
+					break;
+	case CHANNEL_MODULE_RELOAD:	return "RELOAD (Channel module reload)";
+					break;
+	case CHANNEL_CLI_RELOAD:	return "CLIRELOAD (Channel module reload by CLI command)";
+					break;
+	default:	return "MANAGERRELOAD (Channel module reload by manager)";
+					break;
+	}
+};
+	

Modified: team/oej/astum/channels/chan_agent.c
URL: http://svn.digium.com/view/asterisk/team/oej/astum/channels/chan_agent.c?rev=8679&r1=8678&r2=8679&view=diff
==============================================================================
--- team/oej/astum/channels/chan_agent.c (original)
+++ team/oej/astum/channels/chan_agent.c Wed Jan 25 13:41:47 2006
@@ -165,9 +165,6 @@
 
 static int usecnt =0;
 AST_MUTEX_DEFINE_STATIC(usecnt_lock);
-
-/* Protect the interface list (of pvt's) */
-AST_MUTEX_DEFINE_STATIC(agentlock);
 
 static int recordagentcalls = 0;
 static char recordformat[AST_MAX_BUF] = "";
@@ -206,10 +203,10 @@
 	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;        /**< Next Agent in the linked list. */
+	AST_LIST_ENTRY(agent_pvt) list;	/**< Next Agent in the linked list. */
 };
 
-static struct agent_pvt *agents = NULL;  /**< Holds the list of agents (loaded form agents.conf). */
+static AST_LIST_HEAD_STATIC(agents, agent_pvt);	/**< Holds the list of agents (loaded form agents.conf). */
 
 #define CHECK_FORMATS(ast, p) do { \
 	if (p->chan) {\
@@ -280,34 +277,6 @@
 };
 
 /**
- * Unlink (that is, take outside of the linked list) an agent.
- *
- * @param agent Agent to be unlinked.
- */
-static void agent_unlink(struct agent_pvt *agent)
-{
-	struct agent_pvt *p, *prev;
-	prev = NULL;
-	p = agents;
-	/* Iterate over all agents looking for the one. */
-	while(p) {
-		if (p == agent) {
-			/* Once it was found, check if it is the first one. */
-			if (prev)
-				/* 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;
-			else
-				/* If it is the first one, just change the general pointer to point to the second one. */
-				agents = agent->next;
-			/* We are done. */
-			break;
-		}
-		prev = p;
-		p = p->next;
-	}
-}
-
-/**
  * Adds an agent to the global list of agents.
  *
  * @param agent A string with the username, password and real name of an agent. As defined in agents.conf. Example: "13,169,John Smith"
@@ -326,7 +295,7 @@
 	char *password = NULL;
 	char *name = NULL;
 	char *agt = NULL;
-	struct agent_pvt *p, *prev;
+	struct agent_pvt *p;
 
 	if (!(parse = ast_strdupa(agent)))
 		return NULL;
@@ -355,13 +324,9 @@
 	}
 	
 	/* Are we searching for the agent here ? To see if it exists already ? */
-	prev=NULL;
-	p = agents;
-	while(p) {
+	AST_LIST_TRAVERSE(&agents, p, list) {
 		if (!pending && !strcmp(p->agent, agt))
 			break;
-		prev = p;
-		p = p->next;
 	}
 	if (!p) {
 		// Build the agent.
@@ -374,11 +339,7 @@
 		p->app_sleep_cond = 1;
 		p->group = group;
 		p->pending = pending;
-		p->next = NULL;
-		if (prev)
-			prev->next = p;
-		else
-			agents = p;
+		AST_LIST_INSERT_TAIL(&agents, p, list);
 	}
 	
 	ast_copy_string(p->password, password ? password : "", sizeof(p->password));
@@ -824,9 +785,9 @@
 	ast_device_state_changed("Agent/%s", p->agent);
 
 	if (p->pending) {
-		ast_mutex_lock(&agentlock);
-		agent_unlink(p);
-		ast_mutex_unlock(&agentlock);
+		AST_LIST_LOCK(&agents);
+		AST_LIST_REMOVE(&agents, p, list);
+		AST_LIST_UNLOCK(&agents);
 	}
 	if (p->abouttograb) {
 		/* Let the "about to grab" thread know this isn't valid anymore, and let it
@@ -1033,7 +994,7 @@
 {
 	struct ast_config *cfg;
 	struct ast_variable *v;
-	struct agent_pvt *p, *pl, *pn;
+	struct agent_pvt *p;
 	char *general_val;
 
 	group = 0;
@@ -1045,11 +1006,9 @@
 		ast_log(LOG_NOTICE, "No agent configuration found -- agent support disabled\n");
 		return 0;
 	}
-	ast_mutex_lock(&agentlock);
-	p = agents;
-	while(p) {
+	AST_LIST_LOCK(&agents);
+	AST_LIST_TRAVERSE(&agents, p, list) {
 		p->dead = 1;
-		p = p->next;
 	}
 	strcpy(moh, "default");
 	/* set the default recording values */
@@ -1132,16 +1091,9 @@
 		}
 		v = v->next;
 	}
-	p = agents;
-	pl = NULL;
-	while(p) {
-		pn = p->next;
+	AST_LIST_TRAVERSE_SAFE_BEGIN(&agents, p, list) {
 		if (p->dead) {
-			/* Unlink */
-			if (pl)
-				pl->next = p->next;
-			else
-				agents = p->next;
+			AST_LIST_REMOVE_CURRENT(&agents, list);
 			/* Destroy if  appropriate */
 			if (!p->owner) {
 				if (!p->chan) {
@@ -1153,11 +1105,10 @@
 					ast_softhangup(p->chan, AST_SOFTHANGUP_EXPLICIT);
 				}
 			}
-		} else
-			pl = p;
-		p = pn;
-	}
-	ast_mutex_unlock(&agentlock);
+		}
+	}
+	AST_LIST_TRAVERSE_SAFE_END
+	AST_LIST_UNLOCK(&agents);
 	ast_config_destroy(cfg);
 	return 0;
 }
@@ -1171,11 +1122,9 @@
 	if (option_debug)
 		ast_log(LOG_DEBUG, "Checking availability of '%s'\n", newlyavailable->agent);
 	if (needlock)
-		ast_mutex_lock(&agentlock);
-	p = agents;
-	while(p) {
+		AST_LIST_LOCK(&agents);
+	AST_LIST_TRAVERSE(&agents, p, list) {
 		if (p == newlyavailable) {
-			p = p->next;
 			continue;
 		}
 		ast_mutex_lock(&p->lock);
@@ -1190,10 +1139,9 @@
 			break;
 		}
 		ast_mutex_unlock(&p->lock);
-		p = p->next;
 	}
 	if (needlock)
-		ast_mutex_unlock(&agentlock);
+		AST_LIST_UNLOCK(&agents);
 	if (parent && chan)  {
 		if (newlyavailable->ackcall > 1) {
 			/* Don't do beep here */
@@ -1245,11 +1193,9 @@
 
 	ast_log(LOG_DEBUG, "Checking beep availability of '%s'\n", newlyavailable->agent);
 	if (needlock)
-		ast_mutex_lock(&agentlock);
-	p = agents;
-	while(p) {
+		AST_LIST_LOCK(&agents);
+	AST_LIST_TRAVERSE(&agents, p, list) {
 		if (p == newlyavailable) {
-			p = p->next;
 			continue;
 		}
 		ast_mutex_lock(&p->lock);
@@ -1260,10 +1206,9 @@
 			break;
 		}
 		ast_mutex_unlock(&p->lock);
-		p = p->next;
 	}
 	if (needlock)
-		ast_mutex_unlock(&agentlock);
+		AST_LIST_UNLOCK(&agents);
 	if (p) {
 		ast_mutex_unlock(&newlyavailable->lock);
 		if (option_debug > 2)
@@ -1293,11 +1238,9 @@
 
 	snprintf(loginchan, sizeof(loginchan), "%s@%s", chan, !ast_strlen_zero(context) ? context : "default");
 	
-	p = agents;
-	while(p) {
+	AST_LIST_TRAVERSE(&agents, p, list) {
 		if(!strcasecmp(chan, p->loginchan))
 			return 0;
-		p = p->next;
 	}
 	return -1;
 }
@@ -1325,9 +1268,8 @@
 	}
 
 	/* Check actual logged in agents first */
-	ast_mutex_lock(&agentlock);
-	p = agents;
-	while(p) {
+	AST_LIST_LOCK(&agents);
+	AST_LIST_TRAVERSE(&agents, p, list) {
 		ast_mutex_lock(&p->lock);
 		if (!p->pending && ((groupmatch && (p->group & groupmatch)) || !strcmp(data, p->agent)) &&
 		    ast_strlen_zero(p->loginchan)) {
@@ -1346,11 +1288,9 @@
 			}
 		}
 		ast_mutex_unlock(&p->lock);
-		p = p->next;
 	}
 	if (!p) {
-		p = agents;
-		while(p) {
+		AST_LIST_TRAVERSE(&agents, p, list) {
 			ast_mutex_lock(&p->lock);
 			if (!p->pending && ((groupmatch && (p->group & groupmatch)) || !strcmp(data, p->agent))) {
 				if (p->chan || !ast_strlen_zero(p->loginchan))
@@ -1378,7 +1318,6 @@
 				}
 			}
 			ast_mutex_unlock(&p->lock);
-			p = p->next;
 		}
 	}
 
@@ -1401,7 +1340,7 @@
 		*cause = AST_CAUSE_BUSY;
 	else
 		*cause = AST_CAUSE_UNREGISTERED;
-	ast_mutex_unlock(&agentlock);
+	AST_LIST_UNLOCK(&agents);
 	return chan;
 }
 
@@ -1436,9 +1375,8 @@
 	if (!ast_strlen_zero(id))
 		snprintf(idText, sizeof(idText) ,"ActionID: %s\r\n", id);
 	astman_send_ack(s, m, "Agents will follow");
-	ast_mutex_lock(&agentlock);
-	p = agents;
-	while(p) {
+	AST_LIST_LOCK(&agents);
+	AST_LIST_TRAVERSE(&agents, p, list) {
         	ast_mutex_lock(&p->lock);
 
 		/* Status Values:
@@ -1490,9 +1428,8 @@
 			"\r\n",
 			p->agent, username, status, loginChan, (int)p->loginstart, talkingtoChan, idText);
 		ast_mutex_unlock(&p->lock);
-		p = p->next;
-	}
-	ast_mutex_unlock(&agentlock);
+	}
+	AST_LIST_UNLOCK(&agents);
 	ast_cli(s->fd, "Event: AgentsComplete\r\n"
 		"%s"
 		"\r\n",idText);
@@ -1546,7 +1483,7 @@
 	long logintime;
 	int ret = -1; /* Return -1 if no agent if found */
 
-	for (p=agents; p; p=p->next) {
+	AST_LIST_TRAVERSE(&agents, p, list) {
 		if (!strcasecmp(p->agent, agent)) {
 			if (!soft) {
 				if (p->owner) {
@@ -1626,7 +1563,7 @@
 	int which = 0;
 
 	if (pos == 2) {
-		for (p=agents; p; p=p->next) {
+		AST_LIST_TRAVERSE(&agents, p, list) {
 			snprintf(name, sizeof(name), "Agent/%s", p->agent);
 			if (!strncasecmp(word, name, strlen(word))) {
 				if (++which > state) {
@@ -1655,9 +1592,8 @@
 	int offline_agents = 0;		/* Number of offline agents */
 	if (argc != 2)
 		return RESULT_SHOWUSAGE;
-	ast_mutex_lock(&agentlock);
-	p = agents;
-	while(p) {
+	AST_LIST_LOCK(&agents);
+	AST_LIST_TRAVERSE(&agents, p, list) {
 		ast_mutex_lock(&p->lock);
 		if (p->pending) {
 			if (p->group)
@@ -1695,9 +1631,8 @@
 			count_agents++;
 		}
 		ast_mutex_unlock(&p->lock);
-		p = p->next;
-	}
-	ast_mutex_unlock(&agentlock);
+	}
+	AST_LIST_UNLOCK(&agents);
 	if ( !count_agents ) {
 		ast_cli(fd, "No Agents are configured in %s\n",config);
 	} else {
@@ -1822,14 +1757,12 @@
 	while (!res && (max_login_tries==0 || tries < max_login_tries)) {
 		tries++;
 		/* Check for password */
-		ast_mutex_lock(&agentlock);
-		p = agents;
-		while(p) {
+		AST_LIST_LOCK(&agents);
+		AST_LIST_TRAVERSE(&agents, p, list) {
 			if (!strcmp(p->agent, user) && !p->pending)
 				ast_copy_string(xpass, p->password, sizeof(xpass));
-			p = p->next;
-		}
-		ast_mutex_unlock(&agentlock);
+		}
+		AST_LIST_UNLOCK(&agents);
 		if (!res) {
 			if (!ast_strlen_zero(xpass))
 				res = ast_app_getdata(chan, "agent-pass", pass, sizeof(pass) - 1, 0);
@@ -1843,9 +1776,8 @@
 #endif		
 
 		/* Check again for accuracy */
-		ast_mutex_lock(&agentlock);
-		p = agents;
-		while(p) {
+		AST_LIST_LOCK(&agents);
+		AST_LIST_TRAVERSE(&agents, p, list) {
 			ast_mutex_lock(&p->lock);
 			if (!strcmp(p->agent, user) &&
 			    !strcmp(p->password, pass) && !p->pending) {
@@ -1957,12 +1889,12 @@
 						p->acknowledged = 0;
 					}
 					ast_mutex_unlock(&p->lock);
-					ast_mutex_unlock(&agentlock);
+					AST_LIST_UNLOCK(&agents);
 					if( !res && play_announcement==1 )
 						res = ast_streamfile(chan, filename, chan->language);
 					if (!res)
 						ast_waitstream(chan, "");
-					ast_mutex_lock(&agentlock);
+					AST_LIST_LOCK(&agents);
 					ast_mutex_lock(&p->lock);
 					if (!res) {
 						res = ast_set_read_format(chan, ast_best_codec(chan->nativeformats));
@@ -2001,7 +1933,7 @@
 							if (option_verbose > 1)
 								ast_verbose(VERBOSE_PREFIX_2 "Callback Agent '%s' logged out\n", p->agent);
 						}
-						ast_mutex_unlock(&agentlock);
+						AST_LIST_UNLOCK(&agents);
 						if (!res)
 							res = ast_safe_sleep(chan, 500);
 						ast_mutex_unlock(&p->lock);
@@ -2033,7 +1965,7 @@
 						else
 							check_availability(p, 0);
 						ast_mutex_unlock(&p->lock);
-						ast_mutex_unlock(&agentlock);
+						AST_LIST_UNLOCK(&agents);
 						ast_device_state_changed("Agent/%s", p->agent);
 						while (res >= 0) {
 							ast_mutex_lock(&p->lock);
@@ -2045,7 +1977,7 @@
 							if (res)
 								break;
 
-							ast_mutex_lock(&agentlock);
+							AST_LIST_LOCK(&agents);
 							ast_mutex_lock(&p->lock);
 							if (p->lastdisc.tv_sec) {
 								if (ast_tvdiff_ms(ast_tvnow(), p->lastdisc) > p->wrapuptime) {
@@ -2059,7 +1991,7 @@
 								}
 							}
 							ast_mutex_unlock(&p->lock);
-							ast_mutex_unlock(&agentlock);
+							AST_LIST_UNLOCK(&agents);
 							/*	Synchronize channel ownership between call to agent and itself. */
 							ast_mutex_lock( &p->app_lock );
 							ast_mutex_lock(&p->lock);
@@ -2072,11 +2004,11 @@
 												  agent_cont_sleep, p );
 							ast_mutex_unlock( &p->app_lock );
 							if ((p->ackcall > 1)  && (res == 1)) {
-								ast_mutex_lock(&agentlock);
+								AST_LIST_LOCK(&agents);
 								ast_mutex_lock(&p->lock);
 								check_availability(p, 0);
 								ast_mutex_unlock(&p->lock);
-								ast_mutex_unlock(&agentlock);
+								AST_LIST_UNLOCK(&agents);
 								res = 0;
 							}
 							sched_yield();
@@ -2120,10 +2052,9 @@
 				break;
 			}
 			ast_mutex_unlock(&p->lock);
-			p = p->next;
 		}
 		if (!p)
-			ast_mutex_unlock(&agentlock);
+			AST_LIST_UNLOCK(&agents);
 
 		if (!res && (max_login_tries==0 || tries < max_login_tries))
 			res = ast_app_getdata(chan, errmsg, user, sizeof(user) - 1, 0);
@@ -2229,11 +2160,9 @@
 		return 0;
 	}
 
-	ast_mutex_lock(&agentlock);
-	p = agents;
-	while(p) {
+	AST_LIST_LOCK(&agents);
+	AST_LIST_TRAVERSE(&agents, p, list) {
 		if (strcmp(p->agent, agent) || p->pending) {
-			p = p->next;
 			continue;
 		}
 		if (p->chan) {
@@ -2270,9 +2199,8 @@
 			ast_verbose(VERBOSE_PREFIX_2 "Callback Agent '%s' logged in on %s\n", p->agent, p->loginchan);
 		ast_device_state_changed("Agent/%s", p->agent);
 		ast_mutex_unlock(&p->lock);
-		p = p->next;
-	}
-	ast_mutex_unlock(&agentlock);
+	}
+	AST_LIST_UNLOCK(&agents);
 
 	if (login_state == 1)
 		astman_send_ack(s, m, "Agent logged in");
@@ -2313,18 +2241,17 @@
 		char agentvar[AST_MAX_BUF];
 		snprintf(agentvar, sizeof(agentvar), "%s_%s", GETAGENTBYCALLERID, chan->cid.cid_num);
 		if ((tmp = pbx_builtin_getvar_helper(NULL, agentvar))) {
-			struct agent_pvt *p = agents;
+			struct agent_pvt *p;
 			ast_copy_string(agent, tmp, sizeof(agent));
-			ast_mutex_lock(&agentlock);
-			while (p) {
+			AST_LIST_LOCK(&agents);
+			AST_LIST_TRAVERSE(&agents, p, list) {
 				if (!strcasecmp(p->agent, tmp)) {
 					if (changeoutgoing) snprintf(chan->cdr->channel, sizeof(chan->cdr->channel), "Agent/%s", p->agent);
 					__agent_start_monitoring(chan, p, 1);
 					break;
 				}
-				p = p->next;
-			}
-			ast_mutex_unlock(&agentlock);
+			}
+			AST_LIST_UNLOCK(&agents);
 			
 		} else {
 			res = -1;
@@ -2357,7 +2284,7 @@
 	struct agent_pvt *cur_agent = NULL;
 	char buf[256];
 
-	for (cur_agent = agents; cur_agent; cur_agent = cur_agent->next) {
+	AST_LIST_TRAVERSE(&agents, cur_agent, list) {
 		if (cur_agent->chan)
 			continue;
 
@@ -2390,16 +2317,14 @@
 
 	db_tree = ast_db_gettree(pa_family, NULL);
 
-	ast_mutex_lock(&agentlock);
+	AST_LIST_LOCK(&agents);
 	for (entry = db_tree; entry; entry = entry->next) {
 		agent_num = entry->key + strlen(pa_family) + 2;
-		cur_agent = agents;
-		while (cur_agent) {
+		AST_LIST_TRAVERSE(&agents, cur_agent, list) {
 			ast_mutex_lock(&cur_agent->lock);
 			if (strcmp(agent_num, cur_agent->agent) == 0)
 				break;
 			ast_mutex_unlock(&cur_agent->lock);
-			cur_agent = cur_agent->next;
 		}
 		if (!cur_agent) {
 			ast_db_del(pa_family, agent_num);
@@ -2423,7 +2348,7 @@
 			ast_device_state_changed("Agent/%s", cur_agent->agent);	
 		}
 	}
-	ast_mutex_unlock(&agentlock);
+	AST_LIST_UNLOCK(&agents);
 	if (db_tree) {
 		ast_log(LOG_NOTICE, "Agents successfully reloaded from database.\n");
 		ast_db_freetree(db_tree);
@@ -2451,9 +2376,8 @@
 	}
 
 	/* Check actual logged in agents first */
-	ast_mutex_lock(&agentlock);
-	p = agents;
-	while(p) {
+	AST_LIST_LOCK(&agents);
+	AST_LIST_TRAVERSE(&agents, p, list) {
 		ast_mutex_lock(&p->lock);
 		if (!p->pending && ((groupmatch && (p->group & groupmatch)) || !strcmp(data, p->agent))) {
 			if (p->owner) {
@@ -2474,17 +2398,16 @@
 			}
 		}
 		ast_mutex_unlock(&p->lock);
-		p = p->next;
-	}
-	ast_mutex_unlock(&agentlock);
+	}
+	AST_LIST_UNLOCK(&agents);
 	return res;
 }
 
 struct agent_pvt *find_agent(char *agentid)
 {
-	struct agent_pvt *cur = agents;
-
-	for (; cur; cur = cur->next) {
+	struct agent_pvt *cur;
+
+	AST_LIST_TRAVERSE(&agents, cur, list) {
 		if (!strcmp(cur->agent, agentid))
 			break;	
 	}
@@ -2494,8 +2417,11 @@
 
 static char *function_agent(struct ast_channel *chan, char *cmd, char *data, char *buf, size_t len)
 {
-	char *agentid;
-	char *item;
+	char *parse;    
+	AST_DECLARE_APP_ARGS(args,
+		AST_APP_ARG(agentid);
+		AST_APP_ARG(item);
+	);
 	char *tmp;
 	struct agent_pvt *agent;
 
@@ -2506,39 +2432,38 @@
 		return buf;	
 	}
 
-	if (!(item = ast_strdupa(data)))
+	if (!(parse = ast_strdupa(data)))
 		return buf;
 
-	agentid	= strsep(&item, ":");
-	if (!item)
-		item = "status";
-
-	agent = find_agent(agentid);
-	if (!agent) {
-		ast_log(LOG_WARNING, "Agent '%s' not found!\n", agentid);
+	AST_NONSTANDARD_APP_ARGS(args, parse, ':');
+	if (!args.item)
+		args.item = "status";
+
+	if (!(agent = find_agent(args.agentid))) {
+		ast_log(LOG_WARNING, "Agent '%s' not found!\n", args.agentid);
 		return buf;
 	}
 
-	if (!strcasecmp(item, "status")) {
+	if (!strcasecmp(args.item, "status")) {
 		if (agent->chan || !ast_strlen_zero(agent->loginchan)) {
 			ast_copy_string(buf, "LOGGEDIN", len);
 		} else {
 			ast_copy_string(buf, "LOGGEDOUT", len);
 		}
-	} else if (!strcasecmp(item, "password")) {
+	} else if (!strcasecmp(args.item, "password")) {
 		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);
-	} else if (!strcasecmp(item, "mohclass")) {

[... 932 lines stripped ...]


More information about the asterisk-commits mailing list