[asterisk-commits] elguero: trunk r377915 - /trunk/main/features.c

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Tue Dec 11 22:43:21 CST 2012


Author: elguero
Date: Tue Dec 11 22:43:18 2012
New Revision: 377915

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=377915
Log:
Convert Dynamic Features Buffer To Use ast_str

Currently, the biffer for the dynamic features list is set to a fixed size of
128.  If the list is bigger than that, it results in the dynamic feature(s) not
being recognized.

This patch changes the buffer from a fixed size to a dynamic one.

(closes issue ASTERISK-20680)
Reported by: Clod Patry
Tested by: Michael L. Young
Patches: 
    asterisk-20680-dynamic-features-v2.diff 
                                     uploaded by Michael L. Young (license 5026)

Review: https://reviewboard.asterisk.org/r/2221/

Modified:
    trunk/main/features.c

Modified: trunk/main/features.c
URL: http://svnview.digium.com/svn/asterisk/trunk/main/features.c?view=diff&rev=377915&r1=377914&r2=377915
==============================================================================
--- trunk/main/features.c (original)
+++ trunk/main/features.c Tue Dec 11 22:43:18 2012
@@ -3581,7 +3581,7 @@
  * \retval -1 on failure.
  */
 static int feature_interpret_helper(struct ast_channel *chan, struct ast_channel *peer,
-	struct ast_bridge_config *config, const char *code, int sense, char *dynamic_features_buf,
+	struct ast_bridge_config *config, const char *code, int sense, const struct ast_str *dynamic_features_buf,
 	struct ast_flags *features, feature_interpret_op operation, struct ast_call_feature *feature)
 {
 	int x;
@@ -3640,11 +3640,13 @@
 
 	ast_rwlock_unlock(&features_lock);
 
-	if (ast_strlen_zero(dynamic_features_buf) || feature_detected) {
+	ast_assert(dynamic_features_buf != NULL);
+
+	if (!ast_str_strlen(dynamic_features_buf) || feature_detected) {
 		return res;
 	}
 
-	tmp = dynamic_features_buf;
+	tmp = ast_str_buffer(dynamic_features_buf);
 
 	while ((tok = strsep(&tmp, "#"))) {
 		AST_RWLIST_RDLOCK(&feature_groups);
@@ -3717,10 +3719,12 @@
  */
 static int feature_interpret(struct ast_channel *chan, struct ast_channel *peer, struct ast_bridge_config *config, const char *code, int sense) {
 
-	char dynamic_features_buf[128];
+	struct ast_str *dynamic_features_buf;
 	const char *peer_dynamic_features, *chan_dynamic_features;
 	struct ast_flags features;
 	struct ast_call_feature feature;
+	int res;
+
 	if (sense == FEATURE_SENSE_CHAN) {
 		/* Coverity - This uninit_use should be ignored since this macro initializes the flags */
 		ast_copy_flags(&features, &(config->features_caller), AST_FLAGS_ALL);
@@ -3738,11 +3742,19 @@
 	chan_dynamic_features = ast_strdupa(S_OR(pbx_builtin_getvar_helper(chan, "DYNAMIC_FEATURES"),""));
 	ast_channel_unlock(chan);
 
-	snprintf(dynamic_features_buf, sizeof(dynamic_features_buf), "%s%s%s", S_OR(chan_dynamic_features, ""), chan_dynamic_features && peer_dynamic_features ? "#" : "", S_OR(peer_dynamic_features,""));
-
-	ast_debug(3, "Feature interpret: chan=%s, peer=%s, code=%s, sense=%d, features=%d, dynamic=%s\n", ast_channel_name(chan), ast_channel_name(peer), code, sense, features.flags, dynamic_features_buf);
-
-	return feature_interpret_helper(chan, peer, config, code, sense, dynamic_features_buf, &features, FEATURE_INTERPRET_DO, &feature);
+	if (!(dynamic_features_buf = ast_str_create(128))) {
+		return AST_FEATURE_RETURN_PASSDIGITS;
+	}
+
+	ast_str_set(&dynamic_features_buf, 0, "%s%s%s", S_OR(chan_dynamic_features, ""), chan_dynamic_features && peer_dynamic_features ? "#" : "", S_OR(peer_dynamic_features,""));
+
+	ast_debug(3, "Feature interpret: chan=%s, peer=%s, code=%s, sense=%d, features=%d, dynamic=%s\n", ast_channel_name(chan), ast_channel_name(peer), code, sense, features.flags, ast_str_buffer(dynamic_features_buf));
+
+	res = feature_interpret_helper(chan, peer, config, code, sense, dynamic_features_buf, &features, FEATURE_INTERPRET_DO, &feature);
+
+	ast_free(dynamic_features_buf);
+
+	return res;
 }
 
 
@@ -3753,12 +3765,21 @@
 
 /*! \brief Check if a feature exists */
 static int feature_check(struct ast_channel *chan, struct ast_flags *features, char *code) {
-	char *chan_dynamic_features;
+	struct ast_str *chan_dynamic_features;
+	int res;
+
+	if (!(chan_dynamic_features = ast_str_create(128))) {
+		return AST_FEATURE_RETURN_PASSDIGITS;
+	}
 	ast_channel_lock(chan);
-	chan_dynamic_features = ast_strdupa(S_OR(pbx_builtin_getvar_helper(chan, "DYNAMIC_FEATURES"),""));
+	ast_str_set(&chan_dynamic_features, 0, "%s", S_OR(pbx_builtin_getvar_helper(chan, "DYNAMIC_FEATURES"),""));
 	ast_channel_unlock(chan);
 
-	return feature_interpret_helper(chan, NULL, NULL, code, 0, chan_dynamic_features, features, FEATURE_INTERPRET_CHECK, NULL);
+	res = feature_interpret_helper(chan, NULL, NULL, code, 0, chan_dynamic_features, features, FEATURE_INTERPRET_CHECK, NULL);
+
+	ast_free(chan_dynamic_features);
+
+	return res;
 }
 
 static void set_config_flags(struct ast_channel *chan, struct ast_bridge_config *config)




More information about the asterisk-commits mailing list