[asterisk-commits] russell: branch russell/applicationmap_fixup r39054 - in /team/russell/applic...

asterisk-commits at lists.digium.com asterisk-commits at lists.digium.com
Sat Aug 5 21:50:49 MST 2006


Author: russell
Date: Sat Aug  5 23:50:48 2006
New Revision: 39054

URL: http://svn.digium.com/view/asterisk?rev=39054&view=rev
Log:
- move the feature flags from channel.h into res_features.c, since that is the
  only place they are used
- make the existing caller/callee specification *only* apply to who to activate
  the feature on
- run autoservice on the channel not having the application run on them so that
  they are happy when the app takes any amount of time

Modified:
    team/russell/applicationmap_fixup/include/asterisk/channel.h
    team/russell/applicationmap_fixup/res/res_features.c

Modified: team/russell/applicationmap_fixup/include/asterisk/channel.h
URL: http://svn.digium.com/view/asterisk/team/russell/applicationmap_fixup/include/asterisk/channel.h?rev=39054&r1=39053&r2=39054&view=diff
==============================================================================
--- team/russell/applicationmap_fixup/include/asterisk/channel.h (original)
+++ team/russell/applicationmap_fixup/include/asterisk/channel.h Sat Aug  5 23:50:48 2006
@@ -416,16 +416,14 @@
 
 /* @} */
 
-#define AST_FEATURE_PLAY_WARNING	(1 << 0)
-#define AST_FEATURE_REDIRECT		(1 << 1)
-#define AST_FEATURE_DISCONNECT		(1 << 2)
-#define AST_FEATURE_ATXFER		(1 << 3)
-#define AST_FEATURE_AUTOMON		(1 << 4)
-#define AST_FEATURE_PARKCALL		(1 << 5)
-
-#define AST_FEATURE_FLAG_NEEDSDTMF	(1 << 0)
-#define AST_FEATURE_FLAG_CALLEE		(1 << 1)
-#define AST_FEATURE_FLAG_CALLER		(1 << 2)
+enum {
+	AST_FEATURE_PLAY_WARNING = (1 << 0),
+	AST_FEATURE_REDIRECT =     (1 << 1),
+	AST_FEATURE_DISCONNECT =   (1 << 2),
+	AST_FEATURE_ATXFER =       (1 << 3),
+	AST_FEATURE_AUTOMON =      (1 << 4),
+	AST_FEATURE_PARKCALL =     (1 << 5),
+};
 
 struct ast_bridge_config {
 	struct ast_flags features_caller;

Modified: team/russell/applicationmap_fixup/res/res_features.c
URL: http://svn.digium.com/view/asterisk/team/russell/applicationmap_fixup/res/res_features.c?rev=39054&r1=39053&r2=39054&view=diff
==============================================================================
--- team/russell/applicationmap_fixup/res/res_features.c (original)
+++ team/russell/applicationmap_fixup/res/res_features.c Sat Aug  5 23:50:48 2006
@@ -75,6 +75,15 @@
 
 #define AST_MAX_WATCHERS 256
 
+enum {
+	AST_FEATURE_FLAG_NEEDSDTMF = (1 << 0),
+	AST_FEATURE_FLAG_ONCALLEE =  (1 << 1),
+	AST_FEATURE_FLAG_ONCALLER =  (1 << 2),
+	AST_FEATURE_FLAG_BYCALLEE =  (1 << 3),
+	AST_FEATURE_FLAG_BYCALLER =  (1 << 4),
+	AST_FEATURE_FLAG_BYBOTH	 =   (3 << 3),
+};
+
 static char *parkedcall = "ParkedCall";
 
 static int parkaddhints = 0;                               /*!< Add parking hints automatically */
@@ -938,11 +947,12 @@
 {
 	struct ast_app *app;
 	struct ast_call_feature *feature;
+	struct ast_channel *work, *service;
 	int res;
 
 	AST_LIST_LOCK(&feature_list);
-	AST_LIST_TRAVERSE(&feature_list,feature,feature_entry) {
-		if (!strcasecmp(feature->exten,code))
+	AST_LIST_TRAVERSE(&feature_list, feature, feature_entry) {
+		if (!strcasecmp(feature->exten, code))
 			break;
 	}
 	AST_LIST_UNLOCK(&feature_list);
@@ -952,20 +962,24 @@
 		return -1; 
 	}
 	
-	app = pbx_findapp(feature->app);
-	if (app) {
-		struct ast_channel *work = ast_test_flag(feature,AST_FEATURE_FLAG_CALLEE) ? peer : chan;
-		res = pbx_exec(work, app, feature->app_args);
-		if (res == AST_PBX_KEEPALIVE)
-			return FEATURE_RETURN_PBX_KEEPALIVE;
-		else if (res == AST_PBX_NO_HANGUP_PEER)
-			return FEATURE_RETURN_NO_HANGUP_PEER;
-		else if (res)
-			return FEATURE_RETURN_SUCCESSBREAK;
-	} else {
+	if (!(app = pbx_findapp(feature->app))) {
 		ast_log(LOG_WARNING, "Could not find application (%s)\n", feature->app);
 		return -2;
 	}
+	
+	work = ast_test_flag(feature, AST_FEATURE_FLAG_ONCALLEE) ? peer : chan;
+	service = ast_test_flag(feature, AST_FEATURE_FLAG_ONCALLEE) ? chan : peer;
+
+	ast_autoservice_start(service);
+	res = pbx_exec(work, app, feature->app_args);
+	ast_autoservice_stop(service);
+
+	if (res == AST_PBX_KEEPALIVE)
+		return FEATURE_RETURN_PBX_KEEPALIVE;
+	else if (res == AST_PBX_NO_HANGUP_PEER)
+		return FEATURE_RETURN_NO_HANGUP_PEER;
+	else if (res)
+		return FEATURE_RETURN_SUCCESSBREAK;
 	
 	return FEATURE_RETURN_SUCCESS;	/*! \todo XXX should probably return res */
 }
@@ -1076,9 +1090,9 @@
 			/* while we have a feature */
 			while ((tok = strsep(&tmp, "#"))) {
 				if ((feature = find_feature(tok)) && ast_test_flag(feature, AST_FEATURE_FLAG_NEEDSDTMF)) {
-					if (ast_test_flag(feature, AST_FEATURE_FLAG_CALLER))
+					if (ast_test_flag(feature, AST_FEATURE_FLAG_BYCALLER))
 						ast_set_flag(config, AST_BRIDGE_DTMF_CHANNEL_0);
-					if (ast_test_flag(feature, AST_FEATURE_FLAG_CALLEE))
+					if (ast_test_flag(feature, AST_FEATURE_FLAG_BYCALLEE))
 						ast_set_flag(config, AST_BRIDGE_DTMF_CHANNEL_1);
 				}
 			}
@@ -2147,73 +2161,62 @@
 		/* Map a key combination to an application*/
 		ast_unregister_features();
 		for (var = ast_variable_browse(cfg, "applicationmap"); var; var = var->next) {
-			char *tmp_val = ast_strdup(var->value);
-			char *exten, *party=NULL, *app=NULL, *app_args=NULL; 
-
-			if (!tmp_val) { 
-				/*! \todo XXX No memory. We should probably break, but at least we do not
-				 * insist on this entry or we could be stuck in an
-				 * infinite loop.
-				 */
-				continue;
-			}
+			char *tmp_val = ast_strdupa(var->value);
+			char *exten, *activateon, *activatedby, *app, *app_args; 
+			struct ast_call_feature *feature;
 
 			/* strsep() sets the argument to NULL if match not found, and it
 			 * is safe to use it with a NULL argument, so we don't check
 			 * between calls.
 			 */
 			exten = strsep(&tmp_val,",");
-			party = strsep(&tmp_val,",");
+			activatedby = strsep(&tmp_val,",");
 			app = strsep(&tmp_val,",");
 			app_args = strsep(&tmp_val,",");
 
+			activateon = strsep(&activatedby, "/");	
+
 			/*! \todo XXX var_name or app_args ? */
-			if (ast_strlen_zero(app) || ast_strlen_zero(exten) || ast_strlen_zero(party) || ast_strlen_zero(var->name)) {
-				ast_log(LOG_NOTICE, "Please check the feature Mapping Syntax, either extension, name, or app aren't provided %s %s %s %s\n",app,exten,party,var->name);
-				free(tmp_val);
+			if (ast_strlen_zero(app) || ast_strlen_zero(exten) || ast_strlen_zero(activateon) || ast_strlen_zero(var->name)) {
+				ast_log(LOG_NOTICE, "Please check the feature Mapping Syntax, either extension, name, or app aren't provided %s %s %s %s\n",
+					app, exten, activateon, var->name);
 				continue;
 			}
 
-			{
-				struct ast_call_feature *feature;
-				int mallocd = 0;
+			if ((feature = find_feature(var->name))) {
+				ast_log(LOG_WARNING, "Dynamic Feature '%s' specified more than once!\n", var->name);
+				continue;
+			}
+					
+			if (!(feature = ast_calloc(1, sizeof(*feature))))
+				continue;					
+
+			ast_copy_string(feature->sname, var->name, FEATURE_SNAME_LEN);
+			ast_copy_string(feature->app, app, FEATURE_APP_LEN);
+			ast_copy_string(feature->exten, exten, FEATURE_EXTEN_LEN);
+			
+			if (app_args) 
+				ast_copy_string(feature->app_args, app_args, FEATURE_APP_ARGS_LEN);
 				
-				if (!(feature = find_feature(var->name))) {
-					mallocd = 1;
-					
-					if (!(feature = ast_calloc(1, sizeof(*feature)))) {
-						free(tmp_val);
-						continue;					
-					}
-				}
-
-				ast_copy_string(feature->sname,var->name,FEATURE_SNAME_LEN);
-				ast_copy_string(feature->app,app,FEATURE_APP_LEN);
-				ast_copy_string(feature->exten, exten,FEATURE_EXTEN_LEN);
-				free(tmp_val);
+			ast_copy_string(feature->exten, exten, sizeof(feature->exten));
+			feature->operation = feature_exec_app;
+			ast_set_flag(feature, AST_FEATURE_FLAG_NEEDSDTMF);
+
+			ast_set_flag(feature, AST_FEATURE_FLAG_BYBOTH);
+
+			if (!strcasecmp(activateon, "caller"))
+				ast_set_flag(feature, AST_FEATURE_FLAG_ONCALLER);
+			else if (!strcasecmp(activateon, "callee"))
+				ast_set_flag(feature, AST_FEATURE_FLAG_ONCALLEE);
+			else {
+				ast_log(LOG_NOTICE, "Invalid 'activateon' specification for feature '%s', must be caller, or callee\n", var->name);
+				continue;
+			}
+
+			ast_register_feature(feature);
 				
-				if (app_args) 
-					ast_copy_string(feature->app_args,app_args,FEATURE_APP_ARGS_LEN);
-				
-				ast_copy_string(feature->exten, exten,sizeof(feature->exten));
-				feature->operation=feature_exec_app;
-				ast_set_flag(feature,AST_FEATURE_FLAG_NEEDSDTMF);
-				
-				if (!strcasecmp(party,"caller"))
-					ast_set_flag(feature,AST_FEATURE_FLAG_CALLER);
-				else if (!strcasecmp(party, "callee"))
-					ast_set_flag(feature,AST_FEATURE_FLAG_CALLEE);
-				else {
-					ast_log(LOG_NOTICE, "Invalid party specification for feature '%s', must be caller, or callee\n", var->name);
-					continue;
-				}
-
-				ast_register_feature(feature);
-				/* XXX do we need to free it if mallocd ? */
-				
-				if (option_verbose >=1)
-					ast_verbose(VERBOSE_PREFIX_2 "Mapping Feature '%s' to app '%s' with code '%s'\n", var->name, app, exten);  
-			}
+			if (option_verbose >= 1)
+				ast_verbose(VERBOSE_PREFIX_2 "Mapping Feature '%s' to app '%s' with code '%s'\n", var->name, app, exten);  
 		}	 
 	}
 	ast_config_destroy(cfg);



More information about the asterisk-commits mailing list