[asterisk-commits] russell: branch russell/indications r174876 - /team/russell/indications/main/
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Wed Feb 11 09:42:47 CST 2009
Author: russell
Date: Wed Feb 11 09:42:47 2009
New Revision: 174876
URL: http://svn.digium.com/svn-view/asterisk?view=rev&rev=174876
Log:
Reduce code duplication.
Modified:
team/russell/indications/main/indications.c
Modified: team/russell/indications/main/indications.c
URL: http://svn.digium.com/svn-view/asterisk/team/russell/indications/main/indications.c?view=diff&rev=174876&r1=174875&r2=174876
==============================================================================
--- team/russell/indications/main/indications.c (original)
+++ team/russell/indications/main/indications.c Wed Feb 11 09:42:47 2009
@@ -551,13 +551,13 @@
return 0;
}
-/* add a new indication to a ast_tone_zone. ast_tone_zone must exist. if the indication already
- * exists, it will be replaced. */
-static int ast_register_indication(struct ast_tone_zone *zone, const char *indication, const char *tonelist)
+/*!
+ * \note called with the tone zone locked
+ */
+static int ast_register_indication(struct ast_tone_zone *zone, const char *indication,
+ const char *tonelist)
{
struct ast_tone_zone_sound *ts;
-
- ast_tone_zone_lock(zone);
AST_LIST_TRAVERSE_SAFE_BEGIN(&zone->tones, ts, entry) {
if (!strcasecmp(indication, ts->name)) {
@@ -569,19 +569,15 @@
AST_LIST_TRAVERSE_SAFE_END
if (!(ts = ast_calloc(1, sizeof(*ts)))) {
- ast_tone_zone_unlock(zone);
- return -2;
+ return -1;
}
if (!(ts->name = ast_strdup(indication)) || !(ts->data = ast_strdup(tonelist))) {
- ast_tone_zone_unlock(zone);
ast_tone_zone_sound_destroy(ts);
- return -2;
+ return -1;
}
AST_LIST_INSERT_TAIL(&zone->tones, ts, entry);
-
- ast_tone_zone_unlock(zone);
return 0;
}
@@ -654,6 +650,8 @@
created_country = 1;
}
+ ast_tone_zone_lock(tz);
+
if (ast_register_indication(tz, a->argv[3], a->argv[4])) {
ast_log(LOG_WARNING, "Unable to register indication %s/%s\n", a->argv[2], a->argv[3]);
if (created_country) {
@@ -661,6 +659,8 @@
}
res = CLI_FAILURE;
}
+
+ ast_tone_zone_unlock(tz);
tz = ast_tone_zone_unref(tz);
@@ -830,42 +830,6 @@
}
}
-/*!
- * \note This is called with the tone zone locked.
- */
-static void store_tone_zone_sound(struct ast_tone_zone *zone, const char *name,
- const char *val)
-{
- struct ast_tone_zone_sound *ts;
-
- /* Remove the tone if it already existed, we'll redo it with new values */
- AST_LIST_TRAVERSE_SAFE_BEGIN(&zone->tones, ts, entry) {
- if (!strcasecmp(name, ts->name)) {
- AST_LIST_REMOVE_CURRENT(entry);
- ast_tone_zone_sound_destroy(ts);
- break;
- }
- }
- AST_LIST_TRAVERSE_SAFE_END
-
- /* not there, add it to the back */
- if (!(ts = ast_calloc(1, sizeof(*ts)))) {
- return;
- }
-
- if (!(ts->name = ast_strdup(name))) {
- ast_tone_zone_sound_destroy(ts);
- return;
- }
-
- if (!(ts->data = ast_strdup(val))) {
- ast_tone_zone_sound_destroy(ts);
- return;
- }
-
- AST_LIST_INSERT_TAIL(&zone->tones, ts, entry);
-}
-
static void store_config_tone_zone(struct ast_tone_zone *zone, const char *var,
const char *value)
{
@@ -875,7 +839,7 @@
CV_F("ringcadence", store_tone_zone_ring_cadence(zone, value));
CV_F("ringcadance", store_tone_zone_ring_cadence(zone, value));
- store_tone_zone_sound(zone, var, value);
+ ast_register_indication(zone, var, value);
CV_END;
}
More information about the asterisk-commits
mailing list