[asterisk-commits] rmudgett: branch rmudgett/bridge_phase r395487 - in /team/rmudgett/bridge_pha...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Thu Jul 25 19:27:06 CDT 2013
Author: rmudgett
Date: Thu Jul 25 19:27:04 2013
New Revision: 395487
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=395487
Log:
* Fixed feature limits to be more flexible.
* Fixed memory leak and free of unmalloced memory if the feature limits
struct could not be constructed.
* Made bridge_builtin_interval_features.so unloadable.
* Simplified parking's use of its duration interval hook.
Modified:
team/rmudgett/bridge_phase/bridges/bridge_builtin_interval_features.c
team/rmudgett/bridge_phase/include/asterisk/bridge_features.h
team/rmudgett/bridge_phase/main/bridge.c
team/rmudgett/bridge_phase/res/parking/parking_bridge_features.c
Modified: team/rmudgett/bridge_phase/bridges/bridge_builtin_interval_features.c
URL: http://svnview.digium.com/svn/asterisk/team/rmudgett/bridge_phase/bridges/bridge_builtin_interval_features.c?view=diff&rev=395487&r1=395486&r2=395487
==============================================================================
--- team/rmudgett/bridge_phase/bridges/bridge_builtin_interval_features.c (original)
+++ team/rmudgett/bridge_phase/bridges/bridge_builtin_interval_features.c Thu Jul 25 19:27:04 2013
@@ -64,7 +64,7 @@
return -1;
}
-static void limits_interval_playback(struct ast_bridge *bridge, struct ast_bridge_channel *bridge_channel, struct ast_bridge_features_limits *limits, const char *file)
+static void limits_interval_playback(struct ast_bridge_channel *bridge_channel, struct ast_bridge_features_limits *limits, const char *file)
{
if (!strcasecmp(file, "timeleft")) {
unsigned int remaining = ast_tvdiff_ms(limits->quitting_time, ast_tvnow()) / 1000;
@@ -114,11 +114,7 @@
{
struct ast_bridge_features_limits *limits = hook_pvt;
- if (bridge_channel->state != BRIDGE_CHANNEL_STATE_WAIT) {
- return -1;
- }
-
- limits_interval_playback(bridge, bridge_channel, limits, limits->connect_sound);
+ limits_interval_playback(bridge_channel, limits, limits->connect_sound);
return -1;
}
@@ -126,72 +122,75 @@
{
struct ast_bridge_features_limits *limits = hook_pvt;
- if (bridge_channel->state == BRIDGE_CHANNEL_STATE_WAIT) {
- /* If we aren't in the wait state, something more important than this warning is happening and we should skip it. */
- limits_interval_playback(bridge, bridge_channel, limits, limits->warning_sound);
- }
-
- return !limits->frequency ? -1 : limits->frequency;
-}
-
-static void copy_bridge_features_limits(struct ast_bridge_features_limits *dst, struct ast_bridge_features_limits *src)
-{
+ limits_interval_playback(bridge_channel, limits, limits->warning_sound);
+ return limits->frequency ?: -1;
+}
+
+static void bridge_features_limits_copy(struct ast_bridge_features_limits *dst, struct ast_bridge_features_limits *src)
+{
+ ast_string_fields_copy(dst, src);
+ dst->quitting_time = src->quitting_time;
dst->duration = src->duration;
dst->warning = src->warning;
dst->frequency = src->frequency;
- dst->quitting_time = src->quitting_time;
-
- ast_string_field_set(dst, duration_sound, src->duration_sound);
- ast_string_field_set(dst, warning_sound, src->warning_sound);
- ast_string_field_set(dst, connect_sound, src->connect_sound);
+}
+
+static void bridge_features_limits_dtor(void *vdoomed)
+{
+ struct ast_bridge_features_limits *doomed = vdoomed;
+
+ ast_bridge_features_limits_destroy(doomed);
+ ast_module_unref(ast_module_info->self);
}
static int bridge_builtin_set_limits(struct ast_bridge_features *features,
- struct ast_bridge_features_limits *limits, enum ast_bridge_hook_remove_flags remove_flags)
-{
- struct ast_bridge_features_limits *feature_limits;
+ struct ast_bridge_features_limits *limits,
+ enum ast_bridge_hook_remove_flags remove_flags)
+{
+ RAII_VAR(struct ast_bridge_features_limits *, feature_limits, NULL, ao2_cleanup);
if (!limits->duration) {
return -1;
}
- if (features->limits) {
- ast_log(LOG_ERROR, "Tried to apply limits to a feature set that already has limits.\n");
- return -1;
- }
-
- feature_limits = ast_malloc(sizeof(*feature_limits));
+ /* Create limits hook_pvt data. */
+ ast_module_ref(ast_module_info->self);
+ feature_limits = ao2_alloc_options(sizeof(*feature_limits),
+ bridge_features_limits_dtor, AO2_ALLOC_OPT_LOCK_NOLOCK);
if (!feature_limits) {
- return -1;
- }
-
+ ast_module_unref(ast_module_info->self);
+ return -1;
+ }
if (ast_bridge_features_limits_construct(feature_limits)) {
return -1;
}
-
- copy_bridge_features_limits(feature_limits, limits);
- features->limits = feature_limits;
-
-/* BUGBUG feature interval hooks need to be reimplemented to be more stand alone. */
+ bridge_features_limits_copy(feature_limits, limits);
+ feature_limits->quitting_time = ast_tvadd(ast_tvnow(),
+ ast_samp2tv(feature_limits->duration, 1000));
+
+ /* Install limit hooks. */
+ ao2_ref(feature_limits, +1);
if (ast_bridge_interval_hook(features, feature_limits->duration,
- bridge_features_duration_callback, feature_limits, NULL, remove_flags)) {
+ bridge_features_duration_callback, feature_limits, __ao2_cleanup, remove_flags)) {
ast_log(LOG_ERROR, "Failed to schedule the duration limiter to the bridge channel.\n");
- return -1;
- }
-
- feature_limits->quitting_time = ast_tvadd(ast_tvnow(), ast_samp2tv(feature_limits->duration, 1000));
-
+ ao2_ref(feature_limits, -1);
+ return -1;
+ }
if (!ast_strlen_zero(feature_limits->connect_sound)) {
+ ao2_ref(feature_limits, +1);
if (ast_bridge_interval_hook(features, 1,
- bridge_features_connect_callback, feature_limits, NULL, remove_flags)) {
+ bridge_features_connect_callback, feature_limits, __ao2_cleanup, remove_flags)) {
ast_log(LOG_WARNING, "Failed to schedule connect sound to the bridge channel.\n");
- }
- }
-
+ ao2_ref(feature_limits, -1);
+ }
+ }
if (feature_limits->warning && feature_limits->warning < feature_limits->duration) {
- if (ast_bridge_interval_hook(features, feature_limits->duration - feature_limits->warning,
- bridge_features_warning_callback, feature_limits, NULL, remove_flags)) {
+ ao2_ref(feature_limits, +1);
+ if (ast_bridge_interval_hook(features,
+ feature_limits->duration - feature_limits->warning,
+ bridge_features_warning_callback, feature_limits, __ao2_cleanup, remove_flags)) {
ast_log(LOG_WARNING, "Failed to schedule warning sound playback to the bridge channel.\n");
+ ao2_ref(feature_limits, -1);
}
}
@@ -200,17 +199,14 @@
static int unload_module(void)
{
+ ast_bridge_interval_unregister(AST_BRIDGE_BUILTIN_INTERVAL_LIMITS);
return 0;
}
static int load_module(void)
{
- ast_bridge_interval_register(AST_BRIDGE_BUILTIN_INTERVAL_LIMITS, bridge_builtin_set_limits);
-
- /* Bump up our reference count so we can't be unloaded. */
- ast_module_ref(ast_module_info->self);
-
- return AST_MODULE_LOAD_SUCCESS;
+ return ast_bridge_interval_register(AST_BRIDGE_BUILTIN_INTERVAL_LIMITS,
+ bridge_builtin_set_limits);
}
AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Built in bridging interval features");
Modified: team/rmudgett/bridge_phase/include/asterisk/bridge_features.h
URL: http://svnview.digium.com/svn/asterisk/team/rmudgett/bridge_phase/include/asterisk/bridge_features.h?view=diff&rev=395487&r1=395486&r2=395487
==============================================================================
--- team/rmudgett/bridge_phase/include/asterisk/bridge_features.h (original)
+++ team/rmudgett/bridge_phase/include/asterisk/bridge_features.h Thu Jul 25 19:27:04 2013
@@ -237,8 +237,6 @@
struct ao2_container *other_hooks;
/*! Attached interval hooks */
struct ast_heap *interval_hooks;
- /*! Limits feature data */
- struct ast_bridge_features_limits *limits;
/*! Feature flags that are enabled */
struct ast_flags feature_flags;
/*! Used to assign the sequence number to the next interval hook added. */
@@ -298,13 +296,6 @@
* \brief Structure that contains configuration information for the limits feature
*/
struct ast_bridge_features_limits {
- /*! Maximum duration that the channel is allowed to be in the bridge (specified in milliseconds) */
- unsigned int duration;
- /*! Duration into the call when warnings should begin (specified in milliseconds or 0 to disable) */
- unsigned int warning;
- /*! Interval between the warnings (specified in milliseconds or 0 to disable) */
- unsigned int frequency;
-
AST_DECLARE_STRING_FIELDS(
/*! Sound file to play when the maximum duration is reached (if empty, then nothing will be played) */
AST_STRING_FIELD(duration_sound);
@@ -315,6 +306,13 @@
);
/*! Time when the bridge will be terminated by the limits feature */
struct timeval quitting_time;
+
+ /*! Maximum duration that the channel is allowed to be in the bridge (specified in milliseconds) */
+ unsigned int duration;
+ /*! Duration into the call when warnings should begin (specified in milliseconds or 0 to disable) */
+ unsigned int warning;
+ /*! Interval between the warnings (specified in milliseconds or 0 to disable) */
+ unsigned int frequency;
};
/*!
Modified: team/rmudgett/bridge_phase/main/bridge.c
URL: http://svnview.digium.com/svn/asterisk/team/rmudgett/bridge_phase/main/bridge.c?view=diff&rev=395487&r1=395486&r2=395487
==============================================================================
--- team/rmudgett/bridge_phase/main/bridge.c (original)
+++ team/rmudgett/bridge_phase/main/bridge.c Thu Jul 25 19:27:04 2013
@@ -2975,7 +2975,6 @@
memset(limits, 0, sizeof(*limits));
if (ast_string_field_init(limits, 256)) {
- ast_free(limits);
return -1;
}
@@ -2988,13 +2987,14 @@
}
int ast_bridge_features_set_limits(struct ast_bridge_features *features,
- struct ast_bridge_features_limits *limits, enum ast_bridge_hook_remove_flags remove_flags)
+ struct ast_bridge_features_limits *limits,
+ enum ast_bridge_hook_remove_flags remove_flags)
{
if (builtin_interval_handlers[AST_BRIDGE_BUILTIN_INTERVAL_LIMITS]) {
- ast_bridge_builtin_set_limits_fn bridge_features_set_limits_callback;
-
- bridge_features_set_limits_callback = builtin_interval_handlers[AST_BRIDGE_BUILTIN_INTERVAL_LIMITS];
- return bridge_features_set_limits_callback(features, limits, remove_flags);
+ ast_bridge_builtin_set_limits_fn callback;
+
+ callback = builtin_interval_handlers[AST_BRIDGE_BUILTIN_INTERVAL_LIMITS];
+ return callback(features, limits, remove_flags);
}
ast_log(LOG_ERROR, "Attempted to set limits without an AST_BRIDGE_BUILTIN_INTERVAL_LIMITS callback registered.\n");
@@ -3180,13 +3180,6 @@
ao2_ref(hook, -1);
}
features->interval_hooks = ast_heap_destroy(features->interval_hooks);
- }
-
- /* If the features contains a limits pvt, destroy that as well. */
- if (features->limits) {
- ast_bridge_features_limits_destroy(features->limits);
- ast_free(features->limits);
- features->limits = NULL;
}
/* Destroy the miscellaneous other hooks container. */
Modified: team/rmudgett/bridge_phase/res/parking/parking_bridge_features.c
URL: http://svnview.digium.com/svn/asterisk/team/rmudgett/bridge_phase/res/parking/parking_bridge_features.c?view=diff&rev=395487&r1=395486&r2=395487
==============================================================================
--- team/rmudgett/bridge_phase/res/parking/parking_bridge_features.c (original)
+++ team/rmudgett/bridge_phase/res/parking/parking_bridge_features.c Thu Jul 25 19:27:04 2013
@@ -363,12 +363,6 @@
return 0;
}
-static void parking_duration_cb_destroyer(void *hook_pvt)
-{
- struct parked_user *user = hook_pvt;
- ao2_ref(user, -1);
-}
-
/*! \internal
* \brief Interval hook. Pulls a parked call from the parking bridge after the timeout is passed and sets the resolution to timeout.
*
@@ -523,7 +517,7 @@
ao2_ref(user, +1);
if (ast_bridge_interval_hook(features, time_limit,
- parking_duration_callback, user, parking_duration_cb_destroyer, AST_BRIDGE_HOOK_REMOVE_ON_PULL)) {
+ parking_duration_callback, user, __ao2_cleanup, AST_BRIDGE_HOOK_REMOVE_ON_PULL)) {
ast_log(LOG_ERROR, "Failed to apply duration limits to the parking call.\n");
ao2_ref(user, -1);
}
More information about the asterisk-commits
mailing list