aboutsummaryrefslogtreecommitdiffstats
path: root/main/features.c
diff options
context:
space:
mode:
authordvossel <dvossel@f38db490-d61c-443f-a65b-d21fe96a405b>2009-03-19 17:10:09 +0000
committerdvossel <dvossel@f38db490-d61c-443f-a65b-d21fe96a405b>2009-03-19 17:10:09 +0000
commit5704af775c913baa29c294f4ec93dad551bb5dff (patch)
treedfb7d69128ddfead41605d17b19b4c3b940253f7 /main/features.c
parent47c9aae208a4bc5ade15920b5e6eeaa84ffdbfe2 (diff)
Merged revisions 183172 via svnmerge from
https://origsvn.digium.com/svn/asterisk/trunk ................ r183172 | dvossel | 2009-03-19 11:28:33 -0500 (Thu, 19 Mar 2009) | 20 lines Merged revisions 183126 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.4 ........ r183126 | dvossel | 2009-03-19 11:15:16 -0500 (Thu, 19 Mar 2009) | 17 lines Allow disconnect feature before a call is bridged feature.conf has a disconnect option. By default this option is set to '*', but it could be anything. If a user wishes to disconnect a call before the other side answers, only '*' will work, regardless if the disconnect option is set to something else. This is because features are unavailable until bridging takes place. The default disconnect option, '*', was hardcoded in app_dial, which doesn't make any sense from a user perspective since they may expect it to be something different. This patch allows features to be detected from outside of the bridge, but not operated on. In this case, the disconnect feature can be detected before briding and handled outside of features.c. (closes issue #11583) Reported by: sobomax Patches: patch-apps__app_dial.c uploaded by sobomax (license 359) 11583.latest-patch uploaded by murf (license 17) detect_disconnect.diff uploaded by dvossel (license 671) Tested by: sobomax, dvossel Review: http://reviewboard.digium.com/r/195/ ........ ................ git-svn-id: http://svn.digium.com/svn/asterisk/branches/1.6.0@183199 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'main/features.c')
-rw-r--r--main/features.c134
1 files changed, 85 insertions, 49 deletions
diff --git a/main/features.c b/main/features.c
index 0f238a528..ce94f8f10 100644
--- a/main/features.c
+++ b/main/features.c
@@ -672,9 +672,6 @@ static int masq_park_call_announce(struct ast_channel *rchan, struct ast_channel
return masq_park_call(rchan, peer, timeout, extout, 1, orig_chan_name);
}
-#define FEATURE_SENSE_CHAN (1 << 0)
-#define FEATURE_SENSE_PEER (1 << 1)
-
/*!
* \brief set caller and callee according to the direction
* \param caller, callee, peer, chan, sense
@@ -1701,67 +1698,55 @@ static int remap_feature(const char *name, const char *value)
}
/*!
- * \brief Check the dynamic features
- * \param chan,peer,config,code,sense
+ * \brief Helper function for feature_interpret and ast_feature_detect
+ * \param chan,peer,config,code,sense,dynamic_features char buf,feature flags,operation,feature
*
* Lock features list, browse for code, unlock list
+ * If a feature is found and the operation variable is set, that feature's
+ * operation is executed. The first feature found is copied to the feature parameter.
* \retval res on success.
* \retval -1 on failure.
*/
-static int ast_feature_interpret(struct ast_channel *chan, struct ast_channel *peer, struct ast_bridge_config *config, char *code, int sense)
+static int feature_interpret_helper(struct ast_channel *chan, struct ast_channel *peer,
+ struct ast_bridge_config *config, char *code, int sense, char *dynamic_features_buf,
+ struct ast_flags *features, int operation, struct ast_call_feature *feature)
{
int x;
- struct ast_flags features;
- struct ast_call_feature *feature;
struct feature_group *fg = NULL;
struct feature_group_exten *fge;
- const char *peer_dynamic_features, *chan_dynamic_features;
- char dynamic_features_buf[128];
+ struct ast_call_feature *tmpfeature;
char *tmp, *tok;
- int res = FEATURE_RETURN_PASSDIGITS;
+ int res = AST_FEATURE_RETURN_PASSDIGITS;
int feature_detected = 0;
- if (sense == FEATURE_SENSE_CHAN) {
- ast_copy_flags(&features, &(config->features_caller), AST_FLAGS_ALL);
+ if (!(peer && chan && config) && operation) {
+ return -1; /* can not run feature operation */
}
- else {
- ast_copy_flags(&features, &(config->features_callee), AST_FLAGS_ALL);
- }
-
- ast_channel_lock(peer);
- peer_dynamic_features = ast_strdupa(S_OR(pbx_builtin_getvar_helper(peer, "DYNAMIC_FEATURES"),""));
- ast_channel_unlock(peer);
-
- ast_channel_lock(chan);
- 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", chan->name, peer->name, code, sense, features.flags, dynamic_features_buf);
ast_rwlock_rdlock(&features_lock);
for (x = 0; x < FEATURES_COUNT; x++) {
- if ((ast_test_flag(&features, builtin_features[x].feature_mask)) &&
+ if ((ast_test_flag(features, builtin_features[x].feature_mask)) &&
!ast_strlen_zero(builtin_features[x].exten)) {
/* Feature is up for consideration */
if (!strcmp(builtin_features[x].exten, code)) {
- if (option_debug > 2) {
- ast_log(LOG_DEBUG, "Feature detected: fname=%s sname=%s exten=%s\n", builtin_features[x].fname, builtin_features[x].sname, builtin_features[x].exten);
+ ast_debug(3, "Feature detected: fname=%s sname=%s exten=%s\n", builtin_features[x].fname, builtin_features[x].sname, builtin_features[x].exten);
+ if (operation) {
+ res = builtin_features[x].operation(chan, peer, config, code, sense, NULL);
}
- res = builtin_features[x].operation(chan, peer, config, code, sense, NULL);
+ memcpy(feature, &builtin_features[x], sizeof(feature));
feature_detected = 1;
break;
} else if (!strncmp(builtin_features[x].exten, code, strlen(code))) {
- if (res == FEATURE_RETURN_PASSDIGITS)
- res = FEATURE_RETURN_STOREDIGITS;
+ if (res == AST_FEATURE_RETURN_PASSDIGITS)
+ res = AST_FEATURE_RETURN_STOREDIGITS;
}
}
}
ast_rwlock_unlock(&features_lock);
- if (ast_strlen_zero(dynamic_features_buf) || feature_detected)
+ if (ast_strlen_zero(dynamic_features_buf) || feature_detected) {
return res;
+ }
tmp = dynamic_features_buf;
@@ -1774,13 +1759,15 @@ static int ast_feature_interpret(struct ast_channel *chan, struct ast_channel *p
AST_LIST_TRAVERSE(&fg->features, fge, entry) {
if (strcasecmp(fge->exten, code))
continue;
-
- res = fge->feature->operation(chan, peer, config, code, sense, fge->feature);
- if (res != FEATURE_RETURN_KEEPTRYING) {
+ if (operation) {
+ res = fge->feature->operation(chan, peer, config, code, sense, fge->feature);
+ }
+ memcpy(feature, fge->feature, sizeof(feature));
+ if (res != AST_FEATURE_RETURN_KEEPTRYING) {
AST_RWLIST_UNLOCK(&feature_groups);
break;
}
- res = FEATURE_RETURN_PASSDIGITS;
+ res = AST_FEATURE_RETURN_PASSDIGITS;
}
if (fge)
break;
@@ -1790,29 +1777,78 @@ static int ast_feature_interpret(struct ast_channel *chan, struct ast_channel *p
AST_RWLIST_RDLOCK(&feature_list);
- if (!(feature = find_dynamic_feature(tok))) {
+ if (!(tmpfeature = find_dynamic_feature(tok))) {
AST_RWLIST_UNLOCK(&feature_list);
continue;
}
-
+
/* Feature is up for consideration */
- if (!strcmp(feature->exten, code)) {
- ast_verb(3, " Feature Found: %s exten: %s\n",feature->sname, tok);
- res = feature->operation(chan, peer, config, code, sense, feature);
- if (res != FEATURE_RETURN_KEEPTRYING) {
+ if (!strcmp(tmpfeature->exten, code)) {
+ ast_verb(3, " Feature Found: %s exten: %s\n",tmpfeature->sname, tok);
+ if (operation) {
+ res = tmpfeature->operation(chan, peer, config, code, sense, tmpfeature);
+ }
+ memcpy(feature, tmpfeature, sizeof(feature));
+ if (res != AST_FEATURE_RETURN_KEEPTRYING) {
AST_RWLIST_UNLOCK(&feature_list);
break;
}
- res = FEATURE_RETURN_PASSDIGITS;
- } else if (!strncmp(feature->exten, code, strlen(code)))
- res = FEATURE_RETURN_STOREDIGITS;
+ res = AST_FEATURE_RETURN_PASSDIGITS;
+ } else if (!strncmp(tmpfeature->exten, code, strlen(code)))
+ res = AST_FEATURE_RETURN_STOREDIGITS;
AST_RWLIST_UNLOCK(&feature_list);
}
-
+
return res;
}
+/*!
+ * \brief Check the dynamic features
+ * \param chan,peer,config,code,sense
+ *
+ * \retval res on success.
+ * \retval -1 on failure.
+*/
+static int ast_feature_interpret(struct ast_channel *chan, struct ast_channel *peer, struct ast_bridge_config *config, char *code, int sense) {
+
+ char dynamic_features_buf[128];
+ const char *peer_dynamic_features, *chan_dynamic_features;
+ struct ast_flags features;
+ struct ast_call_feature feature;
+ if (sense == FEATURE_SENSE_CHAN) {
+ ast_copy_flags(&features, &(config->features_caller), AST_FLAGS_ALL);
+ }
+ else {
+ ast_copy_flags(&features, &(config->features_callee), AST_FLAGS_ALL);
+ }
+
+ ast_channel_lock(peer);
+ peer_dynamic_features = ast_strdupa(S_OR(pbx_builtin_getvar_helper(peer, "DYNAMIC_FEATURES"),""));
+ ast_channel_unlock(peer);
+
+ ast_channel_lock(chan);
+ 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", chan->name, peer->name, code, sense, features.flags, dynamic_features_buf);
+
+ return feature_interpret_helper(chan, peer, config, code, sense, dynamic_features_buf, &features, 1, &feature);
+}
+
+
+int ast_feature_detect(struct ast_channel *chan, struct ast_flags *features, char *code, struct ast_call_feature *feature) {
+
+ char *dynamic_features;
+ ast_channel_lock(chan);
+ dynamic_features = ast_strdupa(S_OR(pbx_builtin_getvar_helper(chan, "DYNAMIC_FEATURES"),""));
+ ast_channel_unlock(chan);
+
+ return feature_interpret_helper(chan, NULL, NULL, code, 0, dynamic_features, features, 0, feature);
+}
+
static void set_config_flags(struct ast_channel *chan, struct ast_channel *peer, struct ast_bridge_config *config)
{
int x;