summaryrefslogtreecommitdiff
path: root/main/features.c
diff options
context:
space:
mode:
authorMichael L. Young <elgueromexicano@gmail.com>2012-12-12 04:43:18 +0000
committerMichael L. Young <elgueromexicano@gmail.com>2012-12-12 04:43:18 +0000
commitff2414ce864fdc363f3fb4df08a7199f3e7cf461 (patch)
tree73640c48eeeaa8f5fe5a53a4d6eb1a66a503cf57 /main/features.c
parent607a5d898cc52b3f1b4d45e1e95ed07fe1f7dc32 (diff)
Convert Dynamic Features Buffer To Use ast_str
Currently, the buffer 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/ git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@377915 65c4cc65-6c06-0410-ace0-fbb531ad65f3
Diffstat (limited to 'main/features.c')
-rw-r--r--main/features.c41
1 files changed, 31 insertions, 10 deletions
diff --git a/main/features.c b/main/features.c
index 12b89a12d..a4977f258 100644
--- a/main/features.c
+++ b/main/features.c
@@ -3581,7 +3581,7 @@ static int remap_feature(const char *name, const char *value)
* \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 @@ static int feature_interpret_helper(struct ast_channel *chan, struct ast_channel
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_helper(struct ast_channel *chan, struct ast_channel
*/
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 @@ static int feature_interpret(struct ast_channel *chan, struct ast_channel *peer,
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,""));
+ 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));
- 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);
+ res = feature_interpret_helper(chan, peer, config, code, sense, dynamic_features_buf, &features, FEATURE_INTERPRET_DO, &feature);
- return 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 @@ int ast_feature_detect(struct ast_channel *chan, struct ast_flags *features, con
/*! \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)