[asterisk-commits] trunk r15895 - /trunk/apps/app_queue.c

asterisk-commits at lists.digium.com asterisk-commits at lists.digium.com
Tue Mar 28 17:30:31 MST 2006


Author: rizzo
Date: Tue Mar 28 18:30:29 2006
New Revision: 15895

URL: http://svn.digium.com/view/asterisk?rev=15895&view=rev
Log:
Normalize some cli completion code.
On passing, replace strdup with ast_strdup() and remove
the now useless checks for NULL since ast_strdup() can handle
it correctly.


Modified:
    trunk/apps/app_queue.c

Modified: trunk/apps/app_queue.c
URL: http://svn.digium.com/view/asterisk/trunk/apps/app_queue.c?rev=15895&r1=15894&r2=15895&view=diff
==============================================================================
--- trunk/apps/app_queue.c (original)
+++ trunk/apps/app_queue.c Tue Mar 28 18:30:29 2006
@@ -1440,12 +1440,9 @@
 	if (tmp->chan->cid.cid_ani)
 		free(tmp->chan->cid.cid_ani);
 	tmp->chan->cid.cid_ani = NULL;
-	if (qe->chan->cid.cid_num)
-		tmp->chan->cid.cid_num = strdup(qe->chan->cid.cid_num);
-	if (qe->chan->cid.cid_name)
-		tmp->chan->cid.cid_name = strdup(qe->chan->cid.cid_name);
-	if (qe->chan->cid.cid_ani)
-		tmp->chan->cid.cid_ani = strdup(qe->chan->cid.cid_ani);
+	tmp->chan->cid.cid_num = ast_strdup(qe->chan->cid.cid_num);
+	tmp->chan->cid.cid_name = ast_strdup(qe->chan->cid.cid_name);
+	tmp->chan->cid.cid_ani = ast_strdup(qe->chan->cid.cid_ani);
 
 	/* Inherit specially named variables from parent channel */
 	ast_channel_inherit_variables(qe->chan, tmp->chan);
@@ -1724,21 +1721,12 @@
 					} else {
 						if (o->chan->cid.cid_num)
 							free(o->chan->cid.cid_num);
-						o->chan->cid.cid_num = NULL;
+						o->chan->cid.cid_num = ast_strdup(in->cid.cid_num);
+
 						if (o->chan->cid.cid_name)
 							free(o->chan->cid.cid_name);
-						o->chan->cid.cid_name = NULL;
-
-						if (in->cid.cid_num) {
-							o->chan->cid.cid_num = strdup(in->cid.cid_num);
-							if (!o->chan->cid.cid_num)
-								ast_log(LOG_WARNING, "Out of memory\n");	
-						}
-						if (in->cid.cid_name) {
-							o->chan->cid.cid_name = strdup(in->cid.cid_name);
-							if (!o->chan->cid.cid_name)
-								ast_log(LOG_WARNING, "Out of memory\n");	
-						}
+						o->chan->cid.cid_name = ast_strdup(in->cid.cid_name);
+
 						ast_string_field_set(o->chan, accountcode, in->accountcode);
 						o->chan->cdrflags = in->cdrflags;
 
@@ -1749,10 +1737,8 @@
 						}
 						if (o->chan->cid.cid_rdnis) 
 							free(o->chan->cid.cid_rdnis);
-						if (!ast_strlen_zero(in->macroexten))
-							o->chan->cid.cid_rdnis = strdup(in->macroexten);
-						else
-							o->chan->cid.cid_rdnis = strdup(in->exten);
+						o->chan->cid.cid_rdnis =
+								ast_strdup(S_OR(in->macroexten, in->exten));
 						if (ast_call(o->chan, tmpchan, 0)) {
 							ast_log(LOG_NOTICE, "Failed to dial on local channel for call forward to '%s'\n", tmpchan);
 							do_hang(o);
@@ -2097,8 +2083,8 @@
 	if (!ast_strlen_zero(announceoverride))
 		announce = announceoverride;
 
- 	for (;cur; cur = cur->next) {
- 		struct callattempt *tmp = ast_calloc(1, sizeof(*tmp));
+	for (;cur; cur = cur->next) {
+		struct callattempt *tmp = ast_calloc(1, sizeof(*tmp));
 		if (!tmp) {
 			ast_mutex_unlock(&qe->parent->lock);
 			if (use_weight) 
@@ -2682,7 +2668,7 @@
 	}
 
 	if (!(parse = ast_strdupa(data))) 
-		return -1;	
+		return -1;
 
 	AST_STANDARD_APP_ARGS(args, parse);
 
@@ -3501,8 +3487,8 @@
 	
 	AST_LIST_LOCK(&queues);
 	AST_LIST_TRAVERSE(&queues, q, list) {
-		if (!strncasecmp(word, q->name, wordlen) &&  (++which > state)) {
-			ret = strdup(q->name);	
+		if (!strncasecmp(word, q->name, wordlen) && ++which > state) {
+			ret = ast_strdup(q->name);	
 			break;
 		}
 	}
@@ -3766,11 +3752,11 @@
 	case 3:	/* Don't attempt to complete name of member (infinite possibilities) */
 		return NULL;
 	case 4:	/* only one possible match, "to" */
-		return state == 0 ? strdup("to") : NULL;
+		return state == 0 ? ast_strdup("to") : NULL;
 	case 5:	/* <queue> */
 		return complete_queue(line, word, pos, state);
 	case 6: /* only one possible match, "penalty" */
-		return state == 0 ? strdup("penalty") : NULL;
+		return state == 0 ? ast_strdup("penalty") : NULL;
 	case 7:
 		if (state < 100) {	/* 0-99 */
 			char *num;
@@ -3823,23 +3809,23 @@
 	struct ast_call_queue *q;
 	struct member *m;
 
- 	/* 0 - add; 1 - queue; 2 - member; 3 - <member>; 4 - from; 5 - <queue> */
- 	if (pos > 5 || pos < 3)
-  		return NULL;
- 	if (pos == 4)	/* only one possible match, 'from' */
- 		return state == 0 ? strdup("from") : NULL;
-  
- 	if (pos == 5)	/* No need to duplicate code */
-  		return complete_queue(line, word, pos, state);
-  
- 	/* here is the case for 3, <member> */
-	if (!AST_LIST_EMPTY(&queues)) {
+	/* 0 - add; 1 - queue; 2 - member; 3 - <member>; 4 - from; 5 - <queue> */
+	if (pos > 5 || pos < 3)
+		return NULL;
+	if (pos == 4)	/* only one possible match, 'from' */
+		return state == 0 ? ast_strdup("from") : NULL;
+
+	if (pos == 5)	/* No need to duplicate code */
+		return complete_queue(line, word, pos, state);
+
+	/* here is the case for 3, <member> */
+	if (!AST_LIST_EMPTY(&queues)) { /* XXX unnecessary ? the traverse does that for us */
 		AST_LIST_TRAVERSE(&queues, q, list) {
 			ast_mutex_lock(&q->lock);
 			for (m = q->members ; m ; m = m->next) {
 				if (++which > state) {
 					ast_mutex_unlock(&q->lock);
-					return strdup(m->interface);
+					return ast_strdup(m->interface);
 				}
 			}
 			ast_mutex_unlock(&q->lock);



More information about the asterisk-commits mailing list