[asterisk-commits] branch oej/multiparking r8892 - in /team/oej/multiparking: ./ apps/ cdr/ chan...

asterisk-commits at lists.digium.com asterisk-commits at lists.digium.com
Tue Jan 31 14:20:42 MST 2006


Author: oej
Date: Mon Jan 30 03:24:46 2006
New Revision: 8892

URL: http://svn.digium.com/view/asterisk?rev=8892&view=rev
Log:
Updates to trunk

Removed:
    team/oej/multiparking/ChangeLog
Modified:
    team/oej/multiparking/   (props changed)
    team/oej/multiparking/Makefile
    team/oej/multiparking/apps/app_dial.c
    team/oej/multiparking/apps/app_queue.c
    team/oej/multiparking/apps/app_random.c
    team/oej/multiparking/apps/app_voicemail.c
    team/oej/multiparking/asterisk.c
    team/oej/multiparking/cdr/cdr_pgsql.c
    team/oej/multiparking/channel.c
    team/oej/multiparking/channels/chan_agent.c
    team/oej/multiparking/channels/chan_features.c
    team/oej/multiparking/channels/chan_iax2.c
    team/oej/multiparking/channels/chan_sip.c
    team/oej/multiparking/configs/queues.conf.sample
    team/oej/multiparking/configs/sip.conf.sample
    team/oej/multiparking/contrib/scripts/safe_asterisk
    team/oej/multiparking/funcs/func_db.c
    team/oej/multiparking/funcs/func_rand.c
    team/oej/multiparking/include/asterisk/astosp.h
    team/oej/multiparking/include/asterisk/channel.h
    team/oej/multiparking/include/asterisk/stringfields.h
    team/oej/multiparking/manager.c
    team/oej/multiparking/pbx.c
    team/oej/multiparking/res/res_osp.c
    team/oej/multiparking/rtp.c
    team/oej/multiparking/utils.c
    team/oej/multiparking/utils/astman.c

Propchange: team/oej/multiparking/
------------------------------------------------------------------------------
--- svnmerge-blocked (original)
+++ svnmerge-blocked Mon Jan 30 03:24:46 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
+/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/multiparking/
------------------------------------------------------------------------------
--- svnmerge-integrated (original)
+++ svnmerge-integrated Mon Jan 30 03:24:46 2006
@@ -1,1 +1,1 @@
-/trunk:1-8442
+/trunk:1-8706

Modified: team/oej/multiparking/Makefile
URL: http://svn.digium.com/view/asterisk/team/oej/multiparking/Makefile?rev=8892&r1=8891&r2=8892&view=diff
==============================================================================
--- team/oej/multiparking/Makefile (original)
+++ team/oej/multiparking/Makefile Mon Jan 30 03:24:46 2006
@@ -106,7 +106,7 @@
 # Detect the busy signal looking only at tone lengths
 # For example if you have 3 beeps 100ms tone, 100ms silence separated by 500 ms of silence
 BUSYDETECT+= #-DBUSYDETECT_TONEONLY
-# Enforce the detection of busy singal (get rid of false hangups)
+# Enforce the detection of busy signal (get rid of false hangups)
 # Don't use together with -DBUSYDETECT_TONEONLY
 BUSYDETECT+= #-DBUSYDETECT_COMPARE_TONE_AND_SILENCE
 

Modified: team/oej/multiparking/apps/app_dial.c
URL: http://svn.digium.com/view/asterisk/team/oej/multiparking/apps/app_dial.c?rev=8892&r1=8891&r2=8892&view=diff
==============================================================================
--- team/oej/multiparking/apps/app_dial.c (original)
+++ team/oej/multiparking/apps/app_dial.c Mon Jan 30 03:24:46 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/multiparking/apps/app_queue.c
URL: http://svn.digium.com/view/asterisk/team/oej/multiparking/apps/app_queue.c?rev=8892&r1=8891&r2=8892&view=diff
==============================================================================
--- team/oej/multiparking/apps/app_queue.c (original)
+++ team/oej/multiparking/apps/app_queue.c Mon Jan 30 03:24:46 2006
@@ -787,6 +787,30 @@
 	}
 }
 
+static void free_members(struct ast_call_queue *q, int all)
+{
+	/* Free non-dynamic members */
+	struct member *curm, *next, *prev = NULL;
+
+	for (curm = q->members; curm; curm = next) {
+		next = curm->next;
+		if (all || !curm->dynamic) {
+			if (prev)
+				prev->next = next;
+			else
+				q->members = next;
+			free(curm);
+		} else 
+			prev = curm;
+	}
+}
+
+static void destroy_queue(struct ast_call_queue *q)
+{
+	free_members(q, 1);
+	ast_mutex_destroy(&q->lock);
+	free(q);
+}
 
 /*!\brief Reload a single queue via realtime.
    \return Return the queue, or NULL if it doesn't exist.
@@ -838,7 +862,7 @@
 				/* Delete. */
 				AST_LIST_REMOVE(&queues, q, list);
 				ast_mutex_unlock(&q->lock);
-				free(q);
+				destroy_queue(q);
 			} else
 				ast_mutex_unlock(&q->lock);
 		}
@@ -1022,37 +1046,6 @@
 	return res;
 }
 
-static void free_members(struct ast_call_queue *q, int all)
-{
-	/* Free non-dynamic members */
-	struct member *curm, *next, *prev;
-
-	curm = q->members;
-	prev = NULL;
-	while(curm) {
-		next = curm->next;
-		if (all || !curm->dynamic) {
-			if (prev)
-				prev->next = next;
-			else
-				q->members = next;
-			free(curm);
-		} else 
-			prev = curm;
-		curm = next;
-	}
-}
-
-static void destroy_queue(struct ast_call_queue *q)
-{
-	AST_LIST_LOCK(&queues);
-	AST_LIST_REMOVE(&queues, q, list);
-	AST_LIST_UNLOCK(&queues);
-	free_members(q, 1);
-	ast_mutex_destroy(&q->lock);
-	free(q);
-}
-
 static int play_file(struct ast_channel *chan, char *filename)
 {
 	int res;
@@ -1260,6 +1253,9 @@
 	ast_mutex_unlock(&q->lock);
 	if (q->dead && !q->count) {	
 		/* It's dead and nobody is in it, so kill it */
+		AST_LIST_LOCK(&queues);
+		AST_LIST_REMOVE(&queues, q, list);
+		AST_LIST_UNLOCK(&queues);
 		destroy_queue(q);
 	}
 }
@@ -2648,14 +2644,12 @@
 		return -1;
 	}
 
+	if (!(parse = ast_strdupa(data)))
+		return -1;
+
+	AST_STANDARD_APP_ARGS(args, parse);
+
 	LOCAL_USER_ADD(u);
-
-	if (!(parse = ast_strdupa(data))) {
-		LOCAL_USER_REMOVE(u);
-		return -1;
-	}
-
-	AST_STANDARD_APP_ARGS(args, parse);
 
 	if (args.options) {
 		if (strchr(args.options, 'j'))
@@ -2703,14 +2697,12 @@
 		return -1;
 	}
 
+	if (!(parse = ast_strdupa(data))) 
+		return -1;	
+
+	AST_STANDARD_APP_ARGS(args, parse);
+
 	LOCAL_USER_ADD(u);
-
-	if (!(parse = ast_strdupa(data))) {
-		LOCAL_USER_REMOVE(u);
-		return -1;	
-	}
-
-	AST_STANDARD_APP_ARGS(args, parse);
 
 	if (args.options) {
 		if (strchr(args.options, 'j'))
@@ -2760,14 +2752,12 @@
 		return -1;
 	}
 
+	if (!(parse = ast_strdupa(data)))
+		return -1;
+
+	AST_STANDARD_APP_ARGS(args, parse);
+
 	LOCAL_USER_ADD(u);
-
-	if (!(parse = ast_strdupa(data))) {
-		LOCAL_USER_REMOVE(u);
-		return -1;
-	}
-
-	AST_STANDARD_APP_ARGS(args, parse);
 
 	if (ast_strlen_zero(args.interface)) {
 		args.interface = ast_strdupa(chan->name);
@@ -2827,11 +2817,12 @@
 		return -1;
 	}
 
+	if (!(parse = ast_strdupa(data)))
+		return -1;
+
+	AST_STANDARD_APP_ARGS(args, parse);
+
 	LOCAL_USER_ADD(u);
-
-	parse = ast_strdupa(data);
-
-	AST_STANDARD_APP_ARGS(args, parse);
 
 	if (ast_strlen_zero(args.interface)) {
 		args.interface = ast_strdupa(chan->name);
@@ -2885,22 +2876,24 @@
 	int res=-1;
 	int ringing=0;
 	struct localuser *u;
-	char *queuename;
-	char info[512];
-	char *info_ptr = info;
-	char *options = NULL;
-	char *url = NULL;
-	char *announceoverride = NULL;
 	const char *user_priority;
 	const char *max_penalty_str;
 	int prio;
 	int max_penalty;
-	char *queuetimeoutstr = NULL;
 	enum queue_result reason = QUEUE_UNKNOWN;
 
 	/* whether to exit Queue application after the timeout hits */
 	int go_on = 0;
 
+	char *parse;
+	AST_DECLARE_APP_ARGS(args,
+		 AST_APP_ARG(queuename);
+		 AST_APP_ARG(options);
+		 AST_APP_ARG(url);
+		 AST_APP_ARG(announceoverride);
+		 AST_APP_ARG(queuetimeoutstr);
+	);
+	
 	/* Our queue entry */
 	struct queue_ent qe;
 	
@@ -2908,24 +2901,23 @@
 		ast_log(LOG_WARNING, "Queue requires an argument: queuename[|options[|URL][|announceoverride][|timeout]]\n");
 		return -1;
 	}
+	
+	parse = ast_strdupa(data);
+	if (!parse) {
+		ast_log(LOG_ERROR, "Out of memory!\n");
+		return -1;
+	}
+	AST_STANDARD_APP_ARGS(args, parse);
 
 	LOCAL_USER_ADD(u);
 
 	/* Setup our queue entry */
 	memset(&qe, 0, sizeof(qe));
 	qe.start = time(NULL);
-	
-	/* Parse our arguments XXX Check for failure XXX */
-	ast_copy_string(info, (char *) data, sizeof(info));
-	queuename = strsep(&info_ptr, "|");
-	options = strsep(&info_ptr, "|");
-	url = strsep(&info_ptr, "|");
-	announceoverride = strsep(&info_ptr, "|");
-	queuetimeoutstr = info_ptr;
 
 	/* set the expire time based on the supplied timeout; */
-	if (queuetimeoutstr)
-		qe.expire = qe.start + atoi(queuetimeoutstr);
+	if (args.queuetimeoutstr)
+		qe.expire = qe.start + atoi(args.queuetimeoutstr);
 	else
 		qe.expire = 0;
 
@@ -2962,12 +2954,12 @@
 		max_penalty = 0;
 	}
 
-	if (options && (strchr(options, 'r')))
+	if (args.options && (strchr(args.options, 'r')))
 		ringing = 1;
 
 	if (option_debug)  
 		ast_log(LOG_DEBUG, "queue: %s, options: %s, url: %s, announce: %s, expires: %ld, priority: %d\n",
-			queuename, options, url, announceoverride, (long)qe.expire, prio);
+			args.queuename, args.options, args.url, args.announceoverride, (long)qe.expire, prio);
 
 	qe.chan = chan;
 	qe.prio = prio;
@@ -2976,8 +2968,8 @@
 	qe.last_pos = 0;
 	qe.last_periodic_announce_time = time(NULL);
 	qe.last_periodic_announce_sound = 0;
-	if (!join_queue(queuename, &qe, &reason)) {
-		ast_queue_log(queuename, chan->uniqueid, "NONE", "ENTERQUEUE", "%s|%s", url ? url : "",
+	if (!join_queue(args.queuename, &qe, &reason)) {
+		ast_queue_log(args.queuename, chan->uniqueid, "NONE", "ENTERQUEUE", "%s|%s", args.url ? args.url : "",
 			      chan->cid.cid_num ? chan->cid.cid_num : "");
 check_turns:
 		if (ringing) {
@@ -2993,9 +2985,9 @@
 			if (res < 0) {
 				/* Record this abandoned call */
 				record_abandoned(&qe);
-				ast_queue_log(queuename, chan->uniqueid, "NONE", "ABANDON", "%d|%d|%ld", qe.pos, qe.opos, (long)time(NULL) - qe.start);
+				 ast_queue_log(args.queuename, chan->uniqueid, "NONE", "ABANDON", "%d|%d|%ld", qe.pos, qe.opos, (long)time(NULL) - qe.start);
 				if (option_verbose > 2) {
-					ast_verbose(VERBOSE_PREFIX_3 "User disconnected from queue %s while waiting their turn\n", queuename);
+					ast_verbose(VERBOSE_PREFIX_3 "User disconnected from queue %s while waiting their turn\n", args.queuename);
 					res = -1;
 				}
 				break;
@@ -3003,7 +2995,7 @@
 			if (!res) 
 				break;
 			if (valid_exit(&qe, res)) {
-				ast_queue_log(queuename, chan->uniqueid, "NONE", "EXITWITHKEY", "%s|%d", qe.digits, qe.pos);
+				ast_queue_log(args.queuename, chan->uniqueid, "NONE", "EXITWITHKEY", "%s|%d", qe.digits, qe.pos);
 				break;
 			}
 		}
@@ -3022,7 +3014,7 @@
                                         record_abandoned(&qe);
 					reason = QUEUE_TIMEOUT;
 					res = 0;
-					ast_queue_log(queuename, chan->uniqueid,"NONE", "EXITWITHTIMEOUT", "%d", qe.pos);
+					ast_queue_log(args.queuename, chan->uniqueid,"NONE", "EXITWITHTIMEOUT", "%d", qe.pos);
 					break;
 				}
 
@@ -3031,7 +3023,7 @@
 					if (qe.parent->announcefrequency && !ringing)
 						res = say_position(&qe);
 					if (res && valid_exit(&qe, res)) {
-						ast_queue_log(queuename, chan->uniqueid, "NONE", "EXITWITHKEY", "%s|%d", qe.digits, qe.pos);
+						 ast_queue_log(args.queuename, chan->uniqueid, "NONE", "EXITWITHKEY", "%s|%d", qe.digits, qe.pos);
 						break;
 					}
 
@@ -3043,20 +3035,21 @@
 					res = say_periodic_announcement(&qe);
 
 				if (res && valid_exit(&qe, res)) {
-					ast_queue_log(queuename, chan->uniqueid, "NONE", "EXITWITHKEY", "%c|%d", res, qe.pos);
+					ast_queue_log(args.queuename, chan->uniqueid, "NONE", "EXITWITHKEY", "%c|%d", res, qe.pos);
 					break;
 				}
 
 				/* Try calling all queue members for 'timeout' seconds */
-				res = try_calling(&qe, options, announceoverride, url, &go_on);
+				res = try_calling(&qe, args.options, args.announceoverride, args.url, &go_on);
+
 				if (res) {
 					if (res < 0) {
 						if (!qe.handled) {
 							record_abandoned(&qe);
-							ast_queue_log(queuename, chan->uniqueid, "NONE", "ABANDON", "%d|%d|%ld", qe.pos, qe.opos, (long)time(NULL) - qe.start);
+							ast_queue_log(args.queuename, chan->uniqueid, "NONE", "ABANDON", "%d|%d|%ld", qe.pos, qe.opos, (long)time(NULL) - qe.start);
 						}
 					} else if (res > 0)
-						ast_queue_log(queuename, chan->uniqueid, "NONE", "EXITWITHKEY", "%s|%d", qe.digits, qe.pos);
+						 ast_queue_log(args.queuename, chan->uniqueid, "NONE", "EXITWITHKEY", "%s|%d", qe.digits, qe.pos);
 					break;
 				}
 
@@ -3083,7 +3076,7 @@
 					record_abandoned(&qe);
 					reason = QUEUE_TIMEOUT;
 					res = 0;
-					ast_queue_log(queuename, chan->uniqueid,"NONE", "EXITWITHTIMEOUT", "%d", qe.pos);	
+					ast_queue_log(args.queuename, chan->uniqueid,"NONE", "EXITWITHTIMEOUT", "%d", qe.pos);
 					break;
 				}
 
@@ -3091,15 +3084,15 @@
 				res = wait_a_bit(&qe);
 				if (res < 0) {
 					record_abandoned(&qe);
-					ast_queue_log(queuename, chan->uniqueid, "NONE", "ABANDON", "%d|%d|%ld", qe.pos, qe.opos, (long)time(NULL) - qe.start);
+					ast_queue_log(args.queuename, chan->uniqueid, "NONE", "ABANDON", "%d|%d|%ld", qe.pos, qe.opos, (long)time(NULL) - qe.start);
 					if (option_verbose > 2) {
-						ast_verbose(VERBOSE_PREFIX_3 "User disconnected from queue %s when they almost made it\n", queuename);
+						ast_verbose(VERBOSE_PREFIX_3 "User disconnected from queue %s when they almost made it\n", args.queuename);
 						res = -1;
 					}
 					break;
 				}
 				if (res && valid_exit(&qe, res)) {
-					ast_queue_log(queuename, chan->uniqueid, "NONE", "EXITWITHKEY", "%s|%d", qe.digits, qe.pos);
+					ast_queue_log(args.queuename, chan->uniqueid, "NONE", "EXITWITHKEY", "%s|%d", qe.digits, qe.pos);
 					break;
 				}
 				/* exit after 'timeout' cycle if 'n' option enabled */
@@ -3108,7 +3101,7 @@
 						ast_verbose(VERBOSE_PREFIX_3 "Exiting on time-out cycle\n");
 						res = -1;
 					}
-					ast_queue_log(queuename, chan->uniqueid, "NONE", "EXITWITHTIMEOUT", "%d", qe.pos);
+					ast_queue_log(args.queuename, chan->uniqueid, "NONE", "EXITWITHTIMEOUT", "%d", qe.pos);
                                         record_abandoned(&qe);
 					reason = QUEUE_TIMEOUT;
 					res = 0;
@@ -3140,7 +3133,7 @@
 		if (reason != QUEUE_UNKNOWN)
 			set_queue_result(chan, reason);
 	} else {
-		ast_log(LOG_WARNING, "Unable to join queue '%s'\n", queuename);
+		ast_log(LOG_WARNING, "Unable to join queue '%s'\n", args.queuename);
 		set_queue_result(chan, reason);
 		res = 0;
 	}
@@ -3155,16 +3148,16 @@
 	struct localuser *u;
 	struct member *m;
 
-	LOCAL_USER_ACF_ADD(u);
 
 	ast_copy_string(buf, "0", len);
 	
 	if (ast_strlen_zero(data)) {
 		ast_log(LOG_ERROR, "%s requires an argument: queuename\n", cmd);
-		LOCAL_USER_REMOVE(u);
 		return buf;
 	}
 
+	LOCAL_USER_ACF_ADD(u);
+	
 	AST_LIST_LOCK(&queues);
 
 	/* Find the right queue */
@@ -3201,7 +3194,7 @@
 	/* Ensure an otherwise empty list doesn't return garbage */
 	buf[0] = '\0';
 
-	if (!data || ast_strlen_zero(data)) {
+	if (ast_strlen_zero(data)) {
 		ast_log(LOG_ERROR, "QUEUE_MEMBER_LIST requires an argument: queuename\n");
 		return buf;
 	}
@@ -3371,10 +3364,10 @@
 	AST_LIST_TRAVERSE_SAFE_BEGIN(&queues, q, list) {
 		if (q->dead) {
 			AST_LIST_REMOVE_CURRENT(&queues, list);
-			if (!q->count) {
-				free(q);
-			} else
-				ast_log(LOG_WARNING, "XXX Leaking a little memory :( XXX\n");
+			if (!q->count)
+				destroy_queue(q);
+			else
+				ast_log(LOG_DEBUG, "XXX Leaking a little memory :( XXX\n");
 		} else {
 			for (cur = q->members; cur; cur = cur->next)
 				cur->status = ast_device_state(cur->interface);

Modified: team/oej/multiparking/apps/app_random.c
URL: http://svn.digium.com/view/asterisk/team/oej/multiparking/apps/app_random.c?rev=8892&r1=8891&r2=8892&view=diff
==============================================================================
--- team/oej/multiparking/apps/app_random.c (original)
+++ team/oej/multiparking/apps/app_random.c Mon Jan 30 03:24:46 2006
@@ -39,7 +39,7 @@
 #include "asterisk/pbx.h"
 #include "asterisk/module.h"
 
-/* TODO This app should be removed from trunk following the release of 1.4 */
+/*! \todo The Random() app should be removed from trunk following the release of 1.4 */
 
 static char *tdesc = "Random goto";
 

Modified: team/oej/multiparking/apps/app_voicemail.c
URL: http://svn.digium.com/view/asterisk/team/oej/multiparking/apps/app_voicemail.c?rev=8892&r1=8891&r2=8892&view=diff
==============================================================================
--- team/oej/multiparking/apps/app_voicemail.c (original)
+++ team/oej/multiparking/apps/app_voicemail.c Mon Jan 30 03:24:46 2006
@@ -780,13 +780,13 @@
 	return snprintf(dest, len, "%s/msg%04d", dir, num);
 }
 
-/** basically mkdir -p $dest/$context/$ext/$mailbox
- * @dest    String. base directory.
- * @context String. Ignored if is null or empty string.
- * @ext     String. Ignored if is null or empty string.
- * @mailbox String. Ignored if is null or empty string. 
- * @returns 0 on failure, 1 on success.
- * */
+/*! \brief basically mkdir -p $dest/$context/$ext/$mailbox
+ * \param dest    String. base directory.
+ * \param context String. Ignored if is null or empty string.
+ * \param ext     String. Ignored if is null or empty string.
+ * \param mailbox String. Ignored if is null or empty string. 
+ * \return 0 on failure, 1 on success.
+ */
 static int create_dirpath(char *dest, int len, char *context, char *ext, char *mailbox)
 {
 	mode_t	mode = VOICEMAIL_DIR_MODE;

Modified: team/oej/multiparking/asterisk.c
URL: http://svn.digium.com/view/asterisk/team/oej/multiparking/asterisk.c?rev=8892&r1=8891&r2=8892&view=diff
==============================================================================
--- team/oej/multiparking/asterisk.c (original)
+++ team/oej/multiparking/asterisk.c Mon Jan 30 03:24:46 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/multiparking/cdr/cdr_pgsql.c
URL: http://svn.digium.com/view/asterisk/team/oej/multiparking/cdr/cdr_pgsql.c?rev=8892&r1=8891&r2=8892&view=diff
==============================================================================
--- team/oej/multiparking/cdr/cdr_pgsql.c (original)
+++ team/oej/multiparking/cdr/cdr_pgsql.c Mon Jan 30 03:24:46 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/multiparking/channel.c
URL: http://svn.digium.com/view/asterisk/team/oej/multiparking/channel.c?rev=8892&r1=8891&r2=8892&view=diff
==============================================================================
--- team/oej/multiparking/channel.c (original)
+++ team/oej/multiparking/channel.c Mon Jan 30 03:24:46 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/multiparking/channels/chan_agent.c
URL: http://svn.digium.com/view/asterisk/team/oej/multiparking/channels/chan_agent.c?rev=8892&r1=8891&r2=8892&view=diff
==============================================================================
--- team/oej/multiparking/channels/chan_agent.c (original)
+++ team/oej/multiparking/channels/chan_agent.c Mon Jan 30 03:24:46 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);

[... 4403 lines stripped ...]


More information about the asterisk-commits mailing list