[asterisk-commits] branch bweschke/bug_6047 - r7749 in /team/bweschke/bug_6047: ./ apps/ channel...

asterisk-commits at lists.digium.com asterisk-commits at lists.digium.com
Tue Jan 3 15:49:50 CST 2006


Author: bweschke
Date: Tue Jan  3 15:49:42 2006
New Revision: 7749

URL: http://svn.digium.com/view/asterisk?rev=7749&view=rev
Log:
 SVNMerge: Bringing this branch up to date with /trunk


Added:
    team/bweschke/bug_6047/contrib/scripts/safe_asterisk_restart
      - copied unchanged from r7748, trunk/contrib/scripts/safe_asterisk_restart
Removed:
    team/bweschke/bug_6047/ast_expr.y
Modified:
    team/bweschke/bug_6047/   (props changed)
    team/bweschke/bug_6047/apps/app_chanspy.c
    team/bweschke/bug_6047/apps/app_mixmonitor.c
    team/bweschke/bug_6047/apps/app_stack.c
    team/bweschke/bug_6047/ast_expr2.fl
    team/bweschke/bug_6047/ast_expr2f.c
    team/bweschke/bug_6047/autoservice.c
    team/bweschke/bug_6047/channel.c
    team/bweschke/bug_6047/channels/chan_iax2.c
    team/bweschke/bug_6047/channels/chan_sip.c
    team/bweschke/bug_6047/configs/sip.conf.sample
    team/bweschke/bug_6047/file.c
    team/bweschke/bug_6047/image.c
    team/bweschke/bug_6047/include/asterisk/chanspy.h
    team/bweschke/bug_6047/include/asterisk/doxyref.h
    team/bweschke/bug_6047/include/asterisk/image.h
    team/bweschke/bug_6047/include/asterisk/rtp.h
    team/bweschke/bug_6047/manager.c
    team/bweschke/bug_6047/rtp.c

Propchange: team/bweschke/bug_6047/
------------------------------------------------------------------------------
--- svnmerge-integrated (original)
+++ svnmerge-integrated Tue Jan  3 15:49:42 2006
@@ -1,1 +1,1 @@
-/trunk:1-7682
+/trunk:1-7748

Modified: team/bweschke/bug_6047/apps/app_chanspy.c
URL: http://svn.digium.com/view/asterisk/team/bweschke/bug_6047/apps/app_chanspy.c?rev=7749&r1=7748&r2=7749&view=diff
==============================================================================
--- team/bweschke/bug_6047/apps/app_chanspy.c (original)
+++ team/bweschke/bug_6047/apps/app_chanspy.c Tue Jan  3 15:49:42 2006
@@ -211,9 +211,9 @@
 
 static void stop_spying(struct ast_channel *chan, struct ast_channel_spy *spy) 
 {
-	/* If our status has changed, then the channel we're spying on is gone....
+	/* If our status has changed to DONE, then the channel we're spying on is gone....
 	   DON'T TOUCH IT!!!  RUN AWAY!!! */
-	if (spy->status != CHANSPY_RUNNING)
+	if (spy->status == CHANSPY_DONE)
 		return;
 
 	if (!chan)

Modified: team/bweschke/bug_6047/apps/app_mixmonitor.c
URL: http://svn.digium.com/view/asterisk/team/bweschke/bug_6047/apps/app_mixmonitor.c?rev=7749&r1=7748&r2=7749&view=diff
==============================================================================
--- team/bweschke/bug_6047/apps/app_mixmonitor.c (original)
+++ team/bweschke/bug_6047/apps/app_mixmonitor.c Tue Jan  3 15:49:42 2006
@@ -119,9 +119,9 @@
 
 static void stopmon(struct ast_channel *chan, struct ast_channel_spy *spy) 
 {
-	/* If our status has changed, then the channel we're spying on is gone....
+	/* If our status has changed to DONE, then the channel we're spying on is gone....
 	   DON'T TOUCH IT!!!  RUN AWAY!!! */
-	if (spy->status != CHANSPY_RUNNING)
+	if (spy->status == CHANSPY_DONE)
 		return;
 
 	if (!chan)

Modified: team/bweschke/bug_6047/apps/app_stack.c
URL: http://svn.digium.com/view/asterisk/team/bweschke/bug_6047/apps/app_stack.c?rev=7749&r1=7748&r2=7749&view=diff
==============================================================================
--- team/bweschke/bug_6047/apps/app_stack.c (original)
+++ team/bweschke/bug_6047/apps/app_stack.c Tue Jan  3 15:49:42 2006
@@ -54,22 +54,18 @@
 
 static const char *gosub_descrip =
 "Gosub([[context|]exten|]priority)\n"
-"  Jumps to the label specified, saving the return address.\n"
-"  Returns 0 if the label exists or -1 otherwise.\n";
+"  Jumps to the label specified, saving the return address.\n";
 static const char *gosubif_descrip =
-"Gosub(condition?labeliftrue[:labeliffalse])\n"
+"GosubIf(condition?labeliftrue[:labeliffalse])\n"
 "  If the condition is true, then jump to labeliftrue.  If false, jumps to\n"
 "labeliffalse, if specified.  In either case, a jump saves the return point\n"
-"in the dialplan, to be returned to with a Return.\n"
-"  Returns 0 if the label exists or -1 otherwise.\n";
+"in the dialplan, to be returned to with a Return.\n";
 static const char *return_descrip =
 "Return()\n"
-"  Jumps to the last label in the stack, removing it.\n"
-"  Returns 0 if there's a label in the stack or -1 otherwise.\n";
+"  Jumps to the last label on the stack, removing it.\n";
 static const char *pop_descrip =
 "StackPop()\n"
-"  Removes last label in the stack, discarding it.\n"
-"  Always returns 0, even if the stack is empty.\n";
+"  Removes last label on the stack, discarding it.\n";
 
 STANDARD_LOCAL_USER;
 

Modified: team/bweschke/bug_6047/ast_expr2.fl
URL: http://svn.digium.com/view/asterisk/team/bweschke/bug_6047/ast_expr2.fl?rev=7749&r1=7748&r2=7749&view=diff
==============================================================================
--- team/bweschke/bug_6047/ast_expr2.fl (original)
+++ team/bweschke/bug_6047/ast_expr2.fl Tue Jan  3 15:49:42 2006
@@ -98,42 +98,42 @@
 
 int ast_expr(char *expr, char *buf, int length)
 {
-	struct parse_io *io;
+	struct parse_io io;
+	int return_value = 0;
 	
-	io = calloc(sizeof(struct parse_io),1);
-	io->string = expr;  /* to pass to the error routine */
+	memset(&io, 0, sizeof(io));
+	io.string = expr;  /* to pass to the error routine */
 	
-	ast_yylex_init(&io->scanner);
+	ast_yylex_init(&io.scanner);
 	
-	ast_yy_scan_string(expr, io->scanner);
+	ast_yy_scan_string(expr, io.scanner);
 	
-	ast_yyparse ((void *) io);
+	ast_yyparse ((void *) &io);
 
-	ast_yylex_destroy(io->scanner);
+	ast_yylex_destroy(io.scanner);
 
-	if (io->val == NULL) {
+	if (!io.val) {
 		if (length > 1) {
 			strcpy(buf, "0");
-			return 1;
+			return_value = 1;
 		}
 	} else {
-		if (io->val->type == AST_EXPR_integer) {
+		if (io.val->type == AST_EXPR_integer) {
 			int res_length;
 
-			res_length = snprintf(buf, length, "%ld", (long int) io->val->u.i);
-			return res_length <= length ? res_length : length;
+			res_length = snprintf(buf, length, "%ld", (long int) io.val->u.i);
+			return_value = (res_length <= length) ? res_length : length;
 		} else {
 #ifdef STANDALONE
-			strncpy(buf, io->val->u.s, length - 1);
+			strncpy(buf, io.val->u.s, length - 1);
 #else /* !STANDALONE */
-			ast_copy_string(buf, io->val->u.s, length);
+			ast_copy_string(buf, io.val->u.s, length);
 #endif /* STANDALONE */
-			return strlen(buf);
+			return_value = strlen(buf);
 		}
-		free(io->val);
+		free(io.val);
 	}
-	free(io);
-	return 0;
+	return return_value;
 }
 
 int ast_yyerror (const char *s,  yyltype *loc, struct parse_io *parseio )

Modified: team/bweschke/bug_6047/ast_expr2f.c
URL: http://svn.digium.com/view/asterisk/team/bweschke/bug_6047/ast_expr2f.c?rev=7749&r1=7748&r2=7749&view=diff
==============================================================================
--- team/bweschke/bug_6047/ast_expr2f.c (original)
+++ team/bweschke/bug_6047/ast_expr2f.c Tue Jan  3 15:49:42 2006
@@ -2562,42 +2562,42 @@
 
 int ast_expr(char *expr, char *buf, int length)
 {
-	struct parse_io *io;
+	struct parse_io io;
+	int return_value = 0;
 	
-	io = calloc(sizeof(struct parse_io),1);
-	io->string = expr;  /* to pass to the error routine */
+	memset(&io, 0, sizeof(io));
+	io.string = expr;  /* to pass to the error routine */
 	
-	ast_yylex_init(&io->scanner);
+	ast_yylex_init(&io.scanner);
 	
-	ast_yy_scan_string(expr, io->scanner);
+	ast_yy_scan_string(expr, io.scanner);
 	
-	ast_yyparse ((void *) io);
-
-	ast_yylex_destroy(io->scanner);
-
-	if (io->val == NULL) {
+	ast_yyparse ((void *) &io);
+
+	ast_yylex_destroy(io.scanner);
+
+	if (!io.val) {
 		if (length > 1) {
 			strcpy(buf, "0");
-			return 1;
+			return_value = 1;
 		}
 	} else {
-		if (io->val->type == AST_EXPR_integer) {
+		if (io.val->type == AST_EXPR_integer) {
 			int res_length;
 
-			res_length = snprintf(buf, length, "%ld", (long int) io->val->u.i);
-			return res_length <= length ? res_length : length;
+			res_length = snprintf(buf, length, "%ld", (long int) io.val->u.i);
+			return_value = (res_length <= length) ? res_length : length;
 		} else {
 #ifdef STANDALONE
-			strncpy(buf, io->val->u.s, length - 1);
+			strncpy(buf, io.val->u.s, length - 1);
 #else /* !STANDALONE */
-			ast_copy_string(buf, io->val->u.s, length);
+			ast_copy_string(buf, io.val->u.s, length);
 #endif /* STANDALONE */
-			return strlen(buf);
+			return_value = strlen(buf);
 		}
-		free(io->val);
+		free(io.val);
 	}
-	free(io);
-	return 0;
+	return return_value;
 }
 
 int ast_yyerror (const char *s,  yyltype *loc, struct parse_io *parseio )

Modified: team/bweschke/bug_6047/autoservice.c
URL: http://svn.digium.com/view/asterisk/team/bweschke/bug_6047/autoservice.c?rev=7749&r1=7748&r2=7749&view=diff
==============================================================================
--- team/bweschke/bug_6047/autoservice.c (original)
+++ team/bweschke/bug_6047/autoservice.c Tue Jan  3 15:49:42 2006
@@ -53,14 +53,13 @@
 
 #define MAX_AUTOMONS 256
 
-AST_MUTEX_DEFINE_STATIC(autolock);
-
 struct asent {
 	struct ast_channel *chan;
-	struct asent *next;
+	AST_LIST_ENTRY(asent) list;
 };
 
-static struct asent *aslist = NULL;
+static AST_LIST_HEAD_STATIC(aslist, asent);
+
 static pthread_t asthread = AST_PTHREADT_NULL;
 
 static void *autoservice_run(void *ign)
@@ -71,23 +70,20 @@
 	struct ast_channel *chan;
 	struct asent *as;
 	struct ast_frame *f;
+
 	for(;;) {
 		x = 0;
-		ast_mutex_lock(&autolock);
-		as = aslist;
-		while(as) {
+		AST_LIST_LOCK(&aslist);
+		AST_LIST_TRAVERSE(&aslist, as, list) {
 			if (!as->chan->_softhangup) {
 				if (x < MAX_AUTOMONS)
 					mons[x++] = as->chan;
 				else
 					ast_log(LOG_WARNING, "Exceeded maximum number of automatic monitoring events.  Fix autoservice.c\n");
 			}
-			as = as->next;
 		}
-		ast_mutex_unlock(&autolock);
+		AST_LIST_UNLOCK(&aslist);
 
-/* 		if (!aslist)
-			break; */
 		ms = 500;
 		chan = ast_waitfor_n(mons, x, &ms);
 		if (chan) {
@@ -106,62 +102,62 @@
 	int res = -1;
 	struct asent *as;
 	int needstart;
-	ast_mutex_lock(&autolock);
-	needstart = (asthread == AST_PTHREADT_NULL) ? 1 : 0 /* aslist ? 0 : 1 */;
-	as = aslist;
-	while(as) {
+	AST_LIST_LOCK(&aslist);
+
+	/* Check if autoservice thread is executing */
+	needstart = (asthread == AST_PTHREADT_NULL) ? 1 : 0 ;
+
+	/* Check if the channel already has autoservice */
+	AST_LIST_TRAVERSE(&aslist, as, list) {
 		if (as->chan == chan)
 			break;
-		as = as->next;
 	}
+
+	/* If not, start autoservice on channel */
 	if (!as) {
-		as = malloc(sizeof(struct asent));
+		as = calloc(1, sizeof(struct asent));
 		if (as) {
-			memset(as, 0, sizeof(struct asent));
 			as->chan = chan;
-			as->next = aslist;
-			aslist = as;
+			AST_LIST_INSERT_HEAD(&aslist, as, list);
 			res = 0;
 			if (needstart) {
 				if (ast_pthread_create(&asthread, NULL, autoservice_run, NULL)) {
 					ast_log(LOG_WARNING, "Unable to create autoservice thread :(\n");
-					free(aslist);
-					aslist = NULL;
+					/* There will only be a single member in the list at this point,
+					   the one we just added. */
+					AST_LIST_REMOVE(&aslist, as, list);
+					free(as);
 					res = -1;
 				} else
 					pthread_kill(asthread, SIGURG);
 			}
 		}
 	}
-	ast_mutex_unlock(&autolock);
+	AST_LIST_UNLOCK(&aslist);
 	return res;
 }
 
 int ast_autoservice_stop(struct ast_channel *chan)
 {
 	int res = -1;
-	struct asent *as, *prev;
-	ast_mutex_lock(&autolock);
-	as = aslist;
-	prev = NULL;
-	while(as) {
-		if (as->chan == chan)
+	struct asent *as;
+
+	AST_LIST_LOCK(&aslist);
+	AST_LIST_TRAVERSE_SAFE_BEGIN(&aslist, as, list) {	
+		if (as->chan == chan) {
+			AST_LIST_REMOVE_CURRENT(&aslist, list);
+			free(as);
+			if (!chan->_softhangup)
+				res = 0;
 			break;
-		prev = as;
-		as = as->next;
+		}
 	}
-	if (as) {
-		if (prev)
-			prev->next = as->next;
-		else
-			aslist = as->next;
-		free(as);
-		if (!chan->_softhangup)
-			res = 0;
-	}
+	AST_LIST_TRAVERSE_SAFE_END
+
 	if (asthread != AST_PTHREADT_NULL) 
 		pthread_kill(asthread, SIGURG);
-	ast_mutex_unlock(&autolock);
+	AST_LIST_UNLOCK(&aslist);
+
 	/* Wait for it to un-block */
 	while(ast_test_flag(chan, AST_FLAG_BLOCKING))
 		usleep(1000);

Modified: team/bweschke/bug_6047/channel.c
URL: http://svn.digium.com/view/asterisk/team/bweschke/bug_6047/channel.c?rev=7749&r1=7748&r2=7749&view=diff
==============================================================================
--- team/bweschke/bug_6047/channel.c (original)
+++ team/bweschke/bug_6047/channel.c Tue Jan  3 15:49:42 2006
@@ -996,7 +996,7 @@
 	AST_LIST_TRAVERSE(&chan->spies->list, spy, list) {
 		ast_mutex_lock(&spy->lock);
 		if ((spy->type == type) && (spy->status == CHANSPY_RUNNING)) {
-			spy->status = CHANSPY_DONE;
+			spy->status = CHANSPY_STOP;
 			if (ast_test_flag(spy, CHANSPY_TRIGGER_MODE) != CHANSPY_TRIGGER_NONE)
 				ast_cond_signal(&spy->trigger);
 		}

Modified: team/bweschke/bug_6047/channels/chan_iax2.c
URL: http://svn.digium.com/view/asterisk/team/bweschke/bug_6047/channels/chan_iax2.c?rev=7749&r1=7748&r2=7749&view=diff
==============================================================================
--- team/bweschke/bug_6047/channels/chan_iax2.c (original)
+++ team/bweschke/bug_6047/channels/chan_iax2.c Tue Jan  3 15:49:42 2006
@@ -2602,7 +2602,7 @@
 				break;
 			} 
 		} else if (!strcasecmp(tmp->name, "regseconds")) {
-			if (sscanf(tmp->value, "%i", (int *)&regseconds) != 1)
+			if (sscanf(tmp->value, "%ld", (time_t *)&regseconds) != 1)
 				regseconds = 0;
 		} else if (!strcasecmp(tmp->name, "ipaddr")) {
 			inet_aton(tmp->value, &(peer->addr.sin_addr));

Modified: team/bweschke/bug_6047/channels/chan_sip.c
URL: http://svn.digium.com/view/asterisk/team/bweschke/bug_6047/channels/chan_sip.c?rev=7749&r1=7748&r2=7749&view=diff
==============================================================================
--- team/bweschke/bug_6047/channels/chan_sip.c (original)
+++ team/bweschke/bug_6047/channels/chan_sip.c Tue Jan  3 15:49:42 2006
@@ -104,6 +104,7 @@
 
 #define SIPDUMPER
 #define DEFAULT_DEFAULT_EXPIRY  120
+#define DEFAULT_MIN_EXPIRY	60
 #define DEFAULT_MAX_EXPIRY	3600
 #define DEFAULT_REGISTRATION_TIMEOUT	20
 #define DEFAULT_MAX_FORWARDS	"70"
@@ -120,6 +121,7 @@
 #define EXPIRY_GUARD_PCT	0.20	/* Percentage of expires timeout to use when 
 					   below EXPIRY_GUARD_LIMIT */
 
+static int min_expiry = DEFAULT_MIN_EXPIRY;
 static int max_expiry = DEFAULT_MAX_EXPIRY;
 static int default_expiry = DEFAULT_DEFAULT_EXPIRY;
 
@@ -498,9 +500,11 @@
 
 /*! \brief sip_history: Structure for saving transactions within a SIP dialog */
 struct sip_history {
-	char event[80];
-	struct sip_history *next;
+	AST_LIST_ENTRY(sip_history) list;
+	char event[0];	/* actually more, depending on needs */
 };
+
+AST_LIST_HEAD_NOLOCK(sip_history_head, sip_history); /*!< history list, entry in sip_pvt */
 
 /*! \brief sip_auth: Creadentials for authentication to other SIP services */
 struct sip_auth {
@@ -701,7 +705,7 @@
 	struct ast_rtp *rtp;			/*!< RTP Session */
 	struct ast_rtp *vrtp;			/*!< Video RTP session */
 	struct sip_pkt *packets;		/*!< Packets scheduled for re-transmission */
-	struct sip_history *history;		/*!< History of this SIP dialog */
+	struct sip_history_head *history;	/*!< History of this SIP dialog */
 	struct ast_variable *chanvars;		/*!< Channel variables to set for call */
 	struct sip_pvt *next;			/*!< Next call in chain */
 	struct sip_invite_param *options;	/*!< Options for INVITE */
@@ -889,7 +893,7 @@
 /* The list of manual NOTIFY types we know how to send */
 struct ast_config *notify_types;
 
-static struct sip_auth *authl;          /*!< Authentication list */
+static struct sip_auth *authl = NULL;          /*!< Authentication list */
 
 
 static int transmit_response(struct sip_pvt *p, char *msg, struct sip_request *req);
@@ -1135,40 +1139,51 @@
 	return 0;
 }
 
-/*! \brief  append_history: Append to SIP dialog history */
-/*	Always returns 0 */
-static int append_history(struct sip_pvt *p, const char *event, const char *data)
-{
-	struct sip_history *hist, *prev;
-	char *c;
+/*! \brief  append_history: Append to SIP dialog history 
+	\return Always returns 0 */
+#define append_history(p, event, fmt , args... )	append_history_full(p, "%-15s " fmt, event, ## args)
+
+static int append_history_full(struct sip_pvt *p, const char *fmt, ...)
+	__attribute__ ((format (printf, 2, 3)));
+
+/*! \brief  Append to SIP dialog history with arg list  */
+static void append_history_va(struct sip_pvt *p, const char *fmt, va_list ap)
+{
+	char buf[80], *c = buf; /* max history length */
+	struct sip_history *hist;
+	int l;
+
+	vsnprintf(buf, sizeof(buf), fmt, ap);
+	strsep(&c, "\r\n"); /* Trim up everything after \r or \n */
+	l = strlen(buf) + 1;
+	hist = calloc(1, sizeof(*hist) + l);
+	if (!hist) {
+		ast_log(LOG_WARNING, "Can't allocate memory for history");
+		return;
+	}
+	if (p->history == NULL)
+		p->history = calloc(1, sizeof(struct sip_history_head));
+	if (p->history == NULL) {
+		ast_log(LOG_WARNING, "Can't allocate memory for history head");
+		free(hist);
+		return;
+	}
+	memcpy(hist->event, buf, l);
+	AST_LIST_INSERT_TAIL(p->history, hist, list);
+}
+
+/*! \brief  Append to SIP dialog history with arg list  */
+static int append_history_full(struct sip_pvt *p, const char *fmt, ...)
+{
+        va_list ap;
 
 	if (!recordhistory || !p)
 		return 0;
-	if(!(hist = malloc(sizeof(struct sip_history)))) {
-		ast_log(LOG_WARNING, "Can't allocate memory for history");
-		return 0;
-	}
-	memset(hist, 0, sizeof(struct sip_history));
-	snprintf(hist->event, sizeof(hist->event), "%-15s %s", event, data);
-	/* Trim up nicely */
-	c = hist->event;
-	while(*c) {
-		if ((*c == '\r') || (*c == '\n')) {
-			*c = '\0';
-			break;
-		}
-		c++;
-	}
-	/* Enqueue into history */
-	prev = p->history;
-	if (prev) {
-		while(prev->next)
-			prev = prev->next;
-		prev->next = hist;
-	} else {
-		p->history = hist;
-	}
-	return 0;
+        va_start(ap, fmt);
+        append_history_va(p, fmt, ap);
+        va_end(ap);
+
+        return 0;
 }
 
 /*! \brief  retrans_pkt: Retransmit SIP message if no answer ---*/
@@ -1182,8 +1197,6 @@
 	ast_mutex_lock(&pkt->owner->lock);
 
 	if (pkt->retrans < MAX_RETRANS) {
-		char buf[80];
-
 		pkt->retrans++;
  		if (!pkt->timer_t1) {	/* Re-schedule using timer_a and timer_t1 */
 			if (sipdebug && option_debug > 3)
@@ -1215,9 +1228,8 @@
 			else
 				ast_verbose("Retransmitting #%d (no NAT) to %s:%d:\n%s\n---\n", pkt->retrans, ast_inet_ntoa(iabuf, sizeof(iabuf), pkt->owner->sa.sin_addr), ntohs(pkt->owner->sa.sin_port), pkt->data);
 		}
-		snprintf(buf, sizeof(buf), "ReTx %d", reschedule);
-
-		append_history(pkt->owner, buf, pkt->data);
+
+		append_history(pkt->owner, "ReTx", "%d %s", reschedule, pkt->data);
 		__sip_xmit(pkt->owner, pkt->data, pkt->packetlen);
 		ast_mutex_unlock(&pkt->owner->lock);
 		return  reschedule;
@@ -1228,7 +1240,7 @@
 		if ((pkt->method == SIP_OPTIONS) && sipdebug)
 			ast_log(LOG_WARNING, "Cancelling retransmit of OPTIONs (call id %s) \n", pkt->owner->callid);
 	}
-	append_history(pkt->owner, "MaxRetries", (ast_test_flag(pkt, FLAG_FATAL)) ? "(Critical)" : "(Non-critical)");
+	append_history(pkt->owner, "MaxRetries", "%s", (ast_test_flag(pkt, FLAG_FATAL)) ? "(Critical)" : "(Non-critical)");
  		
 	pkt->retransid = -1;
 
@@ -1340,13 +1352,10 @@
 /*! \brief  sip_scheddestroy: Schedule destruction of SIP call ---*/
 static int sip_scheddestroy(struct sip_pvt *p, int ms)
 {
-	char tmp[80];
 	if (sip_debug_test_pvt(p))
 		ast_verbose("Scheduling destruction of call '%s' in %d ms\n", p->callid, ms);
-	if (recordhistory) {
-		snprintf(tmp, sizeof(tmp), "%d ms", ms);
-		append_history(p, "SchedDestroy", tmp);
-	}
+	if (recordhistory)
+		append_history(p, "SchedDestroy", "%d ms", ms);
 
 	if (p->autokillid > -1)
 		ast_sched_del(sched, p->autokillid);
@@ -1478,31 +1487,22 @@
 static int send_response(struct sip_pvt *p, struct sip_request *req, int reliable, int seqno)
 {
 	int res;
-	char iabuf[INET_ADDRSTRLEN];
-	struct sip_request tmp;
-	char tmpmsg[80];
 
 	if (sip_debug_test_pvt(p)) {
+		char iabuf[INET_ADDRSTRLEN];
 		if (ast_test_flag(p, SIP_NAT) & SIP_NAT_ROUTE)
 			ast_verbose("%sTransmitting (NAT) to %s:%d:\n%s\n---\n", reliable ? "Reliably " : "", ast_inet_ntoa(iabuf, sizeof(iabuf), p->recv.sin_addr), ntohs(p->recv.sin_port), req->data);
 		else
 			ast_verbose("%sTransmitting (no NAT) to %s:%d:\n%s\n---\n", reliable ? "Reliably " : "", ast_inet_ntoa(iabuf, sizeof(iabuf), p->sa.sin_addr), ntohs(p->sa.sin_port), req->data);
 	}
-	if (reliable) {
-		if (recordhistory) {
-			parse_copy(&tmp, req);
-			snprintf(tmpmsg, sizeof(tmpmsg), "%s / %s", tmp.data, get_header(&tmp, "CSeq"));
-			append_history(p, "TxRespRel", tmpmsg);
-		}
-		res = __sip_reliable_xmit(p, seqno, 1, req->data, req->len, (reliable > 1), req->method);
-	} else {
-		if (recordhistory) {
-			parse_copy(&tmp, req);
-			snprintf(tmpmsg, sizeof(tmpmsg), "%s / %s", tmp.data, get_header(&tmp, "CSeq"));
-			append_history(p, "TxResp", tmpmsg);
-		}
-		res = __sip_xmit(p, req->data, req->len);
-	}
+	if (recordhistory) {
+		struct sip_request tmp;
+		parse_copy(&tmp, req);
+		append_history(p, reliable ? "TxRespRel" : "TxResp", "%s / %s", tmp.data, get_header(&tmp, "CSeq"));
+	}
+	res = (reliable) ?
+		__sip_reliable_xmit(p, seqno, 1, req->data, req->len, (reliable > 1), req->method) :
+		__sip_xmit(p, req->data, req->len);
 	if (res > 0)
 		return 0;
 	return res;
@@ -1512,31 +1512,22 @@
 static int send_request(struct sip_pvt *p, struct sip_request *req, int reliable, int seqno)
 {
 	int res;
-	char iabuf[INET_ADDRSTRLEN];
-	struct sip_request tmp;
-	char tmpmsg[80];
 
 	if (sip_debug_test_pvt(p)) {
+		char iabuf[INET_ADDRSTRLEN];
 		if (ast_test_flag(p, SIP_NAT) & SIP_NAT_ROUTE)
 			ast_verbose("%sTransmitting (NAT) to %s:%d:\n%s\n---\n", reliable ? "Reliably " : "", ast_inet_ntoa(iabuf, sizeof(iabuf), p->recv.sin_addr), ntohs(p->recv.sin_port), req->data);
 		else
 			ast_verbose("%sTransmitting (no NAT) to %s:%d:\n%s\n---\n", reliable ? "Reliably " : "", ast_inet_ntoa(iabuf, sizeof(iabuf), p->sa.sin_addr), ntohs(p->sa.sin_port), req->data);
 	}
-	if (reliable) {
-		if (recordhistory) {
-			parse_copy(&tmp, req);
-			snprintf(tmpmsg, sizeof(tmpmsg), "%s / %s", tmp.data, get_header(&tmp, "CSeq"));
-			append_history(p, "TxReqRel", tmpmsg);
-		}
-		res = __sip_reliable_xmit(p, seqno, 0, req->data, req->len, (reliable > 1), req->method);
-	} else {
-		if (recordhistory) {
-			parse_copy(&tmp, req);
-			snprintf(tmpmsg, sizeof(tmpmsg), "%s / %s", tmp.data, get_header(&tmp, "CSeq"));
-			append_history(p, "TxReq", tmpmsg);
-		}
-		res = __sip_xmit(p, req->data, req->len);
-	}
+	if (recordhistory) {
+		struct sip_request tmp;
+		parse_copy(&tmp, req);
+		append_history(p, reliable ? "TxReqRel" : "TxReq", "%s / %s", tmp.data, get_header(&tmp, "CSeq"));
+	}
+	res = (reliable) ?
+		__sip_reliable_xmit(p, seqno, 0, req->data, req->len, (reliable > 1), req->method) :
+		__sip_xmit(p, req->data, req->len);
 	return res;
 }
 
@@ -2101,7 +2092,6 @@
 {
 	struct sip_pvt *cur, *prev = NULL;
 	struct sip_pkt *cp;
-	struct sip_history *hist;
 
 	if (sip_debug_test_pvt(p))
 		ast_verbose("Destroying call '%s'\n", p->callid);
@@ -2151,10 +2141,14 @@
 			ast_mutex_unlock(&p->owner->lock);
 	}
 	/* Clear history */
-	while(p->history) {
-		hist = p->history;
-		p->history = p->history->next;
-		free(hist);
+	if (p->history) {
+		while(!AST_LIST_EMPTY(p->history)) {
+			struct sip_history *hist = AST_LIST_FIRST(p->history);
+			AST_LIST_REMOVE_HEAD(p->history, list);
+			free(hist);
+		}
+		free(p->history);
+		p->history = NULL;
 	}
 
 	cur = iflist;
@@ -2212,7 +2206,9 @@
 	ast_copy_string(name, fup->username, sizeof(name));
 
 	/* Check the list of users */
-	u = find_user(name, 1);
+	if (!outgoing)	/* Only check users for incoming calls */
+		u = find_user(name, 1);
+
 	if (u) {
 		inuse = &u->inUse;
 		call_limit = &u->call_limit;
@@ -3636,7 +3632,7 @@
 
 	/* Manager Hold and Unhold events must be generated, if necessary */
 	if (sin.sin_addr.s_addr && !sendonly) {	        
-	        append_history(p, "Unhold", req->data);
+	        append_history(p, "Unhold", "%s", req->data);
 
 		if (callevents && ast_test_flag(p, SIP_CALL_ONHOLD)) {
 			manager_event(EVENT_FLAG_CALL, "Unhold",
@@ -3649,7 +3645,7 @@
 		ast_clear_flag(p, SIP_CALL_ONHOLD);
 	} else {	        
 		/* No address for RTP, we're on hold */
-	        append_history(p, "Hold", req->data);
+	        append_history(p, "Hold", "%s", req->data);
 
 	        if (callevents && !ast_test_flag(p, SIP_CALL_ONHOLD)) {
 			manager_event(EVENT_FLAG_CALL, "Hold",
@@ -5230,11 +5226,8 @@
 	if (!r)
 		return 0;
 
-	if (r->call && recordhistory) {
-		char tmp[80];
-		snprintf(tmp, sizeof(tmp), "Account: %s@%s", r->username, r->hostname);
-		append_history(r->call, "RegistryRenew", tmp);
-	}
+	if (r->call && recordhistory)
+		append_history(r->call, "RegistryRenew", "Account: %s@%s", r->username, r->hostname);
 	/* Since registry's are only added/removed by the the monitor thread, this
 	   may be overkill to reference/dereference at all here */
 	if (sipdebug)
@@ -5335,11 +5328,8 @@
 			ast_log(LOG_WARNING, "Unable to allocate registration call\n");
 			return 0;
 		}
-		if (recordhistory) {
-			char tmp[80];
-			snprintf(tmp, sizeof(tmp), "Account: %s@%s", r->username, r->hostname);
-			append_history(p, "RegistryInit", tmp);
-		}
+		if (recordhistory)
+			append_history(p, "RegistryInit", "Account: %s@%s", r->username, r->hostname);
 		/* Find address to hostname */
 		if (create_addr(p, r->hostname)) {
 			/* we have what we hope is a temporary network error,
@@ -5903,8 +5893,10 @@
 
 	if (p->expire > -1)
 		ast_sched_del(sched, p->expire);
-	if ((expiry < 1) || (expiry > max_expiry))
+	if (expiry > max_expiry)
 		expiry = max_expiry;
+	if (expiry < min_expiry)
+		expiry = min_expiry;
 	if (!ast_test_flag(p, SIP_REALTIME))
 		p->expire = ast_sched_add(sched, (expiry + 10) * 1000, expire_register, p);
 	else
@@ -6846,7 +6838,7 @@
 	return -1;
 }
 
-/*! \brief  check_via: check Via: headers ---*/
+/*! \brief check Via: header for hostname, port and rport request/answer */
 static int check_via(struct sip_pvt *p, struct sip_request *req)
 {
 	char via[256];
@@ -6856,9 +6848,16 @@
 	struct ast_hostent ahp;
 
 	ast_copy_string(via, get_header(req, "Via"), sizeof(via));
+
+	/* Check for rport */
+	c = strstr(via, ";rport");
+	if (c && (c[6] != '='))	/* rport query, not answer */
+		ast_set_flag(p, SIP_NAT_ROUTE);
+
 	c = strchr(via, ';');
 	if (c) 
 		*c = '\0';
+
 	c = strchr(via, ' ');
 	if (c) {
 		*c = '\0';
@@ -6879,9 +6878,7 @@
 		p->sa.sin_family = AF_INET;
 		memcpy(&p->sa.sin_addr, hp->h_addr, sizeof(p->sa.sin_addr));
 		p->sa.sin_port = htons(pt ? atoi(pt) : DEFAULT_SIP_PORT);
-		c = strstr(via, ";rport");
-		if (c && (c[6] != '='))	/* rport query, not answer */
-			ast_set_flag(p, SIP_NAT_ROUTE);
+
 		if (sip_debug_test_pvt(p)) {
 			c = (ast_test_flag(p, SIP_NAT) & SIP_NAT_ROUTE) ? "NAT" : "non-NAT";
 			ast_verbose("Sending to %s : %d (%s)\n", ast_inet_ntoa(iabuf, sizeof(iabuf), p->sa.sin_addr), ntohs(p->sa.sin_port), c);
@@ -6971,7 +6968,7 @@
 	struct sip_user *user = NULL;
 	struct sip_peer *peer;
 	char *of, from[256], *c;
-	char *rpid,rpid_num[50];
+	char *rpid, rpid_num[50];
 	char iabuf[INET_ADDRSTRLEN];
 	int res = 0;
 	char *t;
@@ -6990,13 +6987,13 @@
 
 	ast_copy_string(from, of, sizeof(from));
 	
-	memset(calleridname,0,sizeof(calleridname));
+	memset(calleridname, 0, sizeof(calleridname));
 	get_calleridname(from, calleridname, sizeof(calleridname));
 	if (calleridname[0])
 		ast_copy_string(p->cid_name, calleridname, sizeof(p->cid_name));
 
 	rpid = get_header(req, "Remote-Party-ID");
-	memset(rpid_num,0,sizeof(rpid_num));
+	memset(rpid_num, 0, sizeof(rpid_num));
 	if (!ast_strlen_zero(rpid)) 
 		p->callingpres = get_rpid_num(rpid,rpid_num, sizeof(rpid_num));
 
@@ -7052,11 +7049,13 @@
 		}
 
 		if (p->rtp) {
-			ast_log(LOG_DEBUG, "Setting NAT on RTP to %d\n", (ast_test_flag(p, SIP_NAT) & SIP_NAT_ROUTE));
+			if (option_debug)
+				ast_log(LOG_DEBUG, "Setting NAT on RTP to %d\n", (ast_test_flag(p, SIP_NAT) & SIP_NAT_ROUTE));
 			ast_rtp_setnat(p->rtp, (ast_test_flag(p, SIP_NAT) & SIP_NAT_ROUTE));
 		}
 		if (p->vrtp) {
-			ast_log(LOG_DEBUG, "Setting NAT on VRTP to %d\n", (ast_test_flag(p, SIP_NAT) & SIP_NAT_ROUTE));
+			if (option_debug)
+				ast_log(LOG_DEBUG, "Setting NAT on VRTP to %d\n", (ast_test_flag(p, SIP_NAT) & SIP_NAT_ROUTE));
 			ast_rtp_setnat(p->vrtp, (ast_test_flag(p, SIP_NAT) & SIP_NAT_ROUTE));
 		}
 		if (!(res = check_auth(p, req, p->randdata, sizeof(p->randdata), user->name, user->secret, user->md5secret, sipmethod, uri, reliable, ignore))) {
@@ -8221,6 +8220,7 @@
 	ast_cli(fd, "  MWI NOTIFY mime type:   %s\n", default_notifymime);
 	ast_cli(fd, "  DNS SRV lookup:         %s\n", srvlookup ? "Yes" : "No");
 	ast_cli(fd, "  Pedantic SIP support:   %s\n", pedanticsipchecking ? "Yes" : "No");
+	ast_cli(fd, "  Reg. min duration       %d secs\n", min_expiry);
 	ast_cli(fd, "  Reg. max duration:      %d secs\n", max_expiry);
 	ast_cli(fd, "  Reg. default duration:  %d secs\n", default_expiry);
 	ast_cli(fd, "  Outbound reg. timeout:  %d secs\n", global_reg_timeout);
@@ -8546,9 +8546,7 @@
 static int sip_show_history(int fd, int argc, char *argv[])
 {
 	struct sip_pvt *cur;
-	struct sip_history *hist;
 	size_t len;
-	int x;
 	int found = 0;
 
 	if (argc != 4)
@@ -8559,19 +8557,18 @@
 	ast_mutex_lock(&iflock);
 	for (cur = iflist; cur; cur = cur->next) {
 		if (!strncasecmp(cur->callid, argv[3], len)) {
+			struct sip_history *hist;
+			int x = 0;
+
 			ast_cli(fd,"\n");
 			if (cur->subscribed != NONE)
 				ast_cli(fd, "  * Subscription\n");
 			else
 				ast_cli(fd, "  * SIP Call\n");
-			x = 0;
-			hist = cur->history;
-			while(hist) {
-				x++;
-				ast_cli(fd, "%d. %s\n", x, hist->event);
-				hist = hist->next;
-			}
-			if (!x)
+			if (cur->history)
+				AST_LIST_TRAVERSE(cur->history, hist, list)
+					ast_cli(fd, "%d. %s\n", x++, hist->event);
+			if (x == 0)
 				ast_cli(fd, "Call '%s' has no history\n", cur->callid);
 			found++;
 		}
@@ -8586,7 +8583,7 @@
   lifespan for SIP dialog */
 void sip_dump_history(struct sip_pvt *dialog)
 {
-	int x;
+	int x = 0;
 	struct sip_history *hist;
 
 	if (!dialog)
@@ -8597,11 +8594,9 @@
 		ast_log(LOG_DEBUG, "  * Subscription\n");
 	else
 		ast_log(LOG_DEBUG, "  * SIP Call\n");
-	x = 0;
-	for (hist = dialog->history; hist; hist = hist->next) {
-		x++;
-		ast_log(LOG_DEBUG, "  %d. %s\n", x, hist->event);
-	}
+	if (dialog->history)
+		AST_LIST_TRAVERSE(dialog->history, hist, list)
+			ast_log(LOG_DEBUG, "  %d. %s\n", x++, hist->event);
 	if (!x)
 		ast_log(LOG_DEBUG, "Call '%s' has no history\n", dialog->callid);
 	ast_log(LOG_DEBUG, "\n---------- END SIP HISTORY for '%s' \n", dialog->callid);
@@ -8884,11 +8879,8 @@
  			/* No old challenge */
 		return -1;
 	}
-	if (recordhistory) {
-		char tmp[80];
-		snprintf(tmp, sizeof(tmp), "Try: %d", p->authtries);
-		append_history(p, "RegistryAuth", tmp);
-	}
+	if (recordhistory)
+		append_history(p, "RegistryAuth", "Try: %d", p->authtries);
  	if (sip_debug_test_pvt(p) && p->registry)
  		ast_verbose("Responding to challenge, registration to domain/host name %s\n", p->registry->hostname);
 	return transmit_register(p->registry, SIP_REGISTER, digest, respheader); 
@@ -9029,6 +9021,8 @@
 
  	/* Check if we have separate auth credentials */
  	if ((auth = find_realm_authentication(authl, p->realm))) {
+		ast_log(LOG_WARNING, "use realm [%s] from peer [%s][%s]\n",
+			auth->username, p->peername, p->username);
  		username = auth->username;
  		secret = auth->secret;
  		md5secret = auth->md5secret;
@@ -10816,6 +10810,8 @@
 		if (p->subscribed == DIALOG_INFO_XML) {  
 			if (p->expiry > max_expiry)
 				p->expiry = max_expiry;
+			if (p->expiry < min_expiry)
+				p->expiry = min_expiry;
 		}
 		if (sipdebug || option_debug > 1)
 			ast_log(LOG_DEBUG, "Adding subscription for extension %s context %s for peer %s\n", p->exten, p->context, p->username);
@@ -10833,7 +10829,7 @@
 
 			transmit_response(p, "200 OK", req);
 			transmit_state_notify(p, firststate, 1, 1);	/* Send first notification */
-			append_history(p, "Subscribestatus", ast_extension_state2str(firststate));
+			append_history(p, "Subscribestatus", "%s", ast_extension_state2str(firststate));
 
 			/* remove any old subscription from this peer for the same exten/context,
 			   as the peer has obviously forgotten about it and it's wasteful to wait
@@ -11154,12 +11150,8 @@
 			goto retrylock;
 		}
 		memcpy(&p->recv, &sin, sizeof(p->recv));
-		if (recordhistory) {
-			char tmp[80];
-			/* This is a response, note what it was for */
-			snprintf(tmp, sizeof(tmp), "%s / %s", req.data, get_header(&req, "CSeq"));
-			append_history(p, "Rx", tmp);
-		}
+		if (recordhistory) /* This is a response, note what it was for */
+			append_history(p, "Rx", "%s / %s", req.data, get_header(&req, "CSeq"));
 		nounlock = 0;
 		if (handle_request(p, &req, &sin, &recount, &nounlock) == -1) {
 			/* Request failed */
@@ -12098,7 +12090,7 @@
 		}
 
 		if (realtime && !strcasecmp(v->name, "regseconds")) {
-			if (sscanf(v->value, "%i", (int *)&regseconds) != 1)
+			if (sscanf(v->value, "%ld", (time_t *)&regseconds) != 1)
 				regseconds = 0;
 		} else if (realtime && !strcasecmp(v->name, "ipaddr") && !ast_strlen_zero(v->value) ) {
 			inet_aton(v->value, &(peer->addr.sin_addr));
@@ -12445,6 +12437,10 @@
 			max_expiry = atoi(v->value);
 			if (max_expiry < 1)
 				max_expiry = DEFAULT_MAX_EXPIRY;
+		} else if (!strcasecmp(v->name, "minexpirey") || !strcasecmp(v->name, "minexpiry")) {
+			min_expiry = atoi(v->value);
+			if (min_expiry < 1)
+				min_expiry = DEFAULT_MIN_EXPIRY;
 		} else if (!strcasecmp(v->name, "defaultexpiry") || !strcasecmp(v->name, "defaultexpirey")) {
 			default_expiry = atoi(v->value);
 			if (default_expiry < 1)

Modified: team/bweschke/bug_6047/configs/sip.conf.sample
URL: http://svn.digium.com/view/asterisk/team/bweschke/bug_6047/configs/sip.conf.sample?rev=7749&r1=7748&r2=7749&view=diff
==============================================================================
--- team/bweschke/bug_6047/configs/sip.conf.sample (original)
+++ team/bweschke/bug_6047/configs/sip.conf.sample Tue Jan  3 15:49:42 2006
@@ -59,6 +59,7 @@
 ;tos=184			; Set IP QoS to either a keyword or numeric val
 ;tos=lowdelay			; lowdelay,throughput,reliability,mincost,none
 ;maxexpiry=3600			; Max length of incoming registration we allow
+;minexpiry=60			; Minimum length of registration (default 60)
 ;defaultexpiry=120		; Default length of incoming/outoing registration
 ;notifymimetype=text/plain	; Allow overriding of mime type in MWI NOTIFY
 ;checkmwi=10			; Default time between mailbox checks for peers

Modified: team/bweschke/bug_6047/file.c
URL: http://svn.digium.com/view/asterisk/team/bweschke/bug_6047/file.c?rev=7749&r1=7748&r2=7749&view=diff
==============================================================================
--- team/bweschke/bug_6047/file.c (original)
+++ team/bweschke/bug_6047/file.c Tue Jan  3 15:49:42 2006
@@ -52,46 +52,46 @@
 #include "asterisk/pbx.h"
 
 struct ast_format {
-	/* Name of format */
+	/*! Name of format */
 	char name[80];
-	/* Extensions (separated by | if more than one) 
-	   this format can read.  First is assumed for writing (e.g. .mp3) */
+	/*! Extensions (separated by | if more than one) 
+	    this format can read.  First is assumed for writing (e.g. .mp3) */
 	char exts[80];
-	/* Format of frames it uses/provides (one only) */
+	/*! Format of frames it uses/provides (one only) */
 	int format;
-	/* Open an input stream, and start playback */
+	/*! Open an input stream, and start playback */
 	struct ast_filestream * (*open)(FILE * f);
-	/* Open an output stream, of a given file descriptor and comment it appropriately if applicable */
+	/*! Open an output stream, of a given file descriptor and comment it appropriately if applicable */
 	struct ast_filestream * (*rewrite)(FILE *f, const char *comment);
-	/* Write a frame to a channel */
+	/*! Write a frame to a channel */
 	int (*write)(struct ast_filestream *, struct ast_frame *);
-	/* seek num samples into file, whence(think normal seek) */
+	/*! seek num samples into file, whence(think normal seek) */
 	int (*seek)(struct ast_filestream *, long offset, int whence);
-	/* trunc file to current position */
+	/*! trunc file to current position */
 	int (*trunc)(struct ast_filestream *fs);
-	/* tell current position */
+	/*! tell current position */
 	long (*tell)(struct ast_filestream *fs);
-	/* Read the next frame from the filestream (if available) and report when to get next one
+	/*! Read the next frame from the filestream (if available) and report when to get next one
 		(in samples) */
 	struct ast_frame * (*read)(struct ast_filestream *, int *whennext);
-	/* Close file, and destroy filestream structure */
+	/*! Close file, and destroy filestream structure */
 	void (*close)(struct ast_filestream *);
-	/* Retrieve file comment */
+	/*! Retrieve file comment */
 	char * (*getcomment)(struct ast_filestream *);
-	/* Link */
+	/*! Link */
 	struct ast_format *next;
 };
 
 struct ast_filestream {
-	/* Everybody reserves a block of AST_RESERVED_POINTERS pointers for us */
+	/*! Everybody reserves a block of AST_RESERVED_POINTERS pointers for us */
 	struct ast_format *fmt;
 	int flags;
 	mode_t mode;
 	char *filename;
 	char *realfilename;
-	/* Video file stream */
+	/*! Video file stream */
 	struct ast_filestream *vfs;
-	/* Transparently translate from another format -- just once */
+	/*! Transparently translate from another format -- just once */
 	struct ast_trans_pvt *trans;
 	struct ast_tranlator_pvt *tr;
 	int lastwriteformat;

Modified: team/bweschke/bug_6047/image.c
URL: http://svn.digium.com/view/asterisk/team/bweschke/bug_6047/image.c?rev=7749&r1=7748&r2=7749&view=diff
==============================================================================
--- team/bweschke/bug_6047/image.c (original)
+++ team/bweschke/bug_6047/image.c Tue Jan  3 15:49:42 2006
@@ -46,37 +46,31 @@
 #include "asterisk/cli.h"
 #include "asterisk/lock.h"
 
-static struct ast_imager *list;
-AST_MUTEX_DEFINE_STATIC(listlock);
+static AST_LIST_HEAD_STATIC(imagers, ast_imager);
 
 int ast_image_register(struct ast_imager *img)
 {
 	if (option_verbose > 1)
 		ast_verbose(VERBOSE_PREFIX_2 "Registered format '%s' (%s)\n", img->name, img->desc);
-	ast_mutex_lock(&listlock);
-	img->next = list;
-	list = img;
-	ast_mutex_unlock(&listlock);
+	AST_LIST_LOCK(&imagers);
+	AST_LIST_INSERT_HEAD(&imagers, img, list);
+	AST_LIST_UNLOCK(&imagers);
 	return 0;
 }
 
 void ast_image_unregister(struct ast_imager *img)
 {
-	struct ast_imager *i, *prev = NULL;
-	ast_mutex_lock(&listlock);
-	i = list;
-	while(i) {
+	struct ast_imager *i;
+	
+	AST_LIST_LOCK(&imagers);
+	AST_LIST_TRAVERSE_SAFE_BEGIN(&imagers, i, list) {	
 		if (i == img) {
-			if (prev) 
-				prev->next = i->next;
-			else
-				list = i->next;
+			AST_LIST_REMOVE_CURRENT(&imagers, list);
 			break;
 		}
-		prev = i;
-		i = i->next;
-	}
-	ast_mutex_unlock(&listlock);
+	}
+	AST_LIST_TRAVERSE_SAFE_END
+	AST_LIST_UNLOCK(&imagers);
 	if (i && (option_verbose > 1))
 		ast_verbose(VERBOSE_PREFIX_2 "Unregistered format '%s' (%s)\n", img->name, img->desc);
 }
@@ -125,11 +119,9 @@
 	int fd;
 	int len=0;
 	struct ast_frame *f = NULL;
-#if 0 /* We need to have some sort of read-only lock */
-	ast_mutex_lock(&listlock);
-#endif	
-	i = list;
-	while(!found && i) {
+	
+	AST_LIST_LOCK(&imagers);
+	AST_LIST_TRAVERSE(&imagers, i, list) {
 		if (i->format & format) {
 			char *stringp=NULL;
 			strncpy(tmp, i->exts, sizeof(tmp)-1);
@@ -149,8 +141,10 @@
 				e = strsep(&stringp, "|");
 			}
 		}
-		i = i->next;
-	}
+		if (found)
+			break;	
+	}
+
 	if (found) {
 		fd = open(buf, O_RDONLY);
 		if (fd > -1) {
@@ -165,9 +159,9 @@

[... 617 lines stripped ...]


More information about the asterisk-commits mailing list