[asterisk-commits] trunk r20597 - /trunk/res/res_features.c

asterisk-commits at lists.digium.com asterisk-commits at lists.digium.com
Sun Apr 16 11:37:03 MST 2006


Author: rizzo
Date: Sun Apr 16 13:37:01 2006
New Revision: 20597

URL: http://svn.digium.com/view/asterisk?rev=20597&view=rev
Log:
minor readability fixes in preparation for more work on this file:
- replace nested 'if' with '&&'
- fix indentation
- annotate the end brace of some huge block
- remove useless parentheses


Modified:
    trunk/res/res_features.c

Modified: trunk/res/res_features.c
URL: http://svn.digium.com/view/asterisk/trunk/res/res_features.c?rev=20597&r1=20596&r2=20597&view=diff
==============================================================================
--- trunk/res/res_features.c (original)
+++ trunk/res/res_features.c Sun Apr 16 13:37:01 2006
@@ -294,10 +294,7 @@
 	}
 	pu->start = ast_tvnow();
 	pu->parkingnum = x;
-	if (timeout > 0)
-		pu->parkingtime = timeout;
-	else
-		pu->parkingtime = parkingtime;
+	pu->parkingtime = (timeout > 0) ? timeout : parkingtime;
 	if (extout)
 		*extout = x;
 	if (peer) 
@@ -425,12 +422,10 @@
 		return -1;
 	}
 
-	if (!monitor_app) { 
-		if (!(monitor_app = pbx_findapp("Monitor"))) {
-			monitor_ok=0;
-			ast_log(LOG_ERROR,"Cannot record the call. The monitor application is disabled.\n");
-			return -1;
-		}
+	if (!monitor_app && !(monitor_app = pbx_findapp("Monitor"))) {
+		monitor_ok=0;
+		ast_log(LOG_ERROR,"Cannot record the call. The monitor application is disabled.\n");
+		return -1;
 	}
 	if (!ast_strlen_zero(courtesytone)) {
 		if (ast_autoservice_start(callee_chan))
@@ -848,7 +843,8 @@
 /*! \brief unregister feature from feature_list */
 void ast_unregister_feature(struct ast_call_feature *feature)
 {
-	if (!feature) return;
+	if (!feature)
+		return;
 
 	AST_LIST_LOCK(&feature_list);
 	AST_LIST_REMOVE(&feature_list,feature,feature_entry);
@@ -902,9 +898,7 @@
 	
 	app = pbx_findapp(feature->app);
 	if (app) {
-		struct ast_channel *work = chan;
-		if (ast_test_flag(feature, AST_FEATURE_FLAG_CALLEE))
-			work = peer;
+		struct ast_channel *work = ast_test_flag(feature,AST_FEATURE_FLAG_CALLEE) ? peer : chan;
 		res = pbx_exec(work, app, feature->app_args);
 		if (res < 0)
 			return res; 
@@ -913,7 +907,7 @@
 		return -2;
 	}
 	
-	return FEATURE_RETURN_SUCCESS;
+	return FEATURE_RETURN_SUCCESS;	/* XXX should probably return res */
 }
 
 static void unmap_features(void)
@@ -1018,26 +1012,23 @@
 			char *tok;
 			struct ast_call_feature *feature;
 
-			if (!tmp) {
+			if (!tmp)	/* no memory */
 				return;
-			}
 
 			/* while we have a feature */
 			while (NULL != (tok = strsep(&tmp, "#"))) {
-				if ((feature = find_feature(tok))) {
-					if (ast_test_flag(feature, AST_FEATURE_FLAG_NEEDSDTMF)) {
-						if (ast_test_flag(feature, AST_FEATURE_FLAG_CALLER))
-							ast_set_flag(config, AST_BRIDGE_DTMF_CHANNEL_0);
-						if (ast_test_flag(feature, AST_FEATURE_FLAG_CALLEE))
-							ast_set_flag(config, AST_BRIDGE_DTMF_CHANNEL_1);
-					}
+				if ((feature = find_feature(tok)) && ast_test_flag(feature, AST_FEATURE_FLAG_NEEDSDTMF)) {
+					if (ast_test_flag(feature, AST_FEATURE_FLAG_CALLER))
+						ast_set_flag(config, AST_BRIDGE_DTMF_CHANNEL_0);
+					if (ast_test_flag(feature, AST_FEATURE_FLAG_CALLEE))
+						ast_set_flag(config, AST_BRIDGE_DTMF_CHANNEL_1);
 				}
 			}
 		}
 	}
 }
 
-
+/* XXX this is very similar to the code in channel.c */
 static struct ast_channel *ast_feature_request_and_dial(struct ast_channel *caller, const char *type, int format, void *data, int timeout, int *outstate, const char *cid_num, const char *cid_name)
 {
 	int state = 0;
@@ -1340,10 +1331,11 @@
 			return -1;
 		}
 		
-		if (!f || ((f->frametype == AST_FRAME_CONTROL) && ((f->subclass == AST_CONTROL_HANGUP) || (f->subclass == AST_CONTROL_BUSY) || 
-			(f->subclass == AST_CONTROL_CONGESTION)))) {
-				res = -1;
-				break;
+		if (!f || (f->frametype == AST_FRAME_CONTROL &&
+				(f->subclass == AST_CONTROL_HANGUP || f->subclass == AST_CONTROL_BUSY || 
+					f->subclass == AST_CONTROL_CONGESTION ) ) ) {
+			res = -1;
+			break;
 		}
 		/* many things should be sent to the 'other' channel */
 		other = (who == chan) ? peer : chan;
@@ -1362,7 +1354,7 @@
 			}
 		}
 		/* check for '*', if we find it it's time to disconnect */
-		if (f && (f->frametype == AST_FRAME_DTMF)) {
+		if (f && f->frametype == AST_FRAME_DTMF) {
 			char *featurecode;
 			int sense;
 
@@ -1576,7 +1568,7 @@
 							goto std;	/* XXX Ick: jumping into an else statement??? XXX */
 						}
 					}
-				}
+				} /* end for */
 				if (x >= AST_MAX_FDS) {
 std:					for (x=0; x<AST_MAX_FDS; x++) {
 						/* Keep this one for next one */
@@ -1594,7 +1586,7 @@
 					pu = pu->next;
 				}
 			}
-		}
+		} /* end while */
 		ast_mutex_unlock(&parking_lock);
 		rfds = nrfds;
 		efds = nefds;



More information about the asterisk-commits mailing list