[asterisk-commits] jpeeler: branch jpeeler/feature14882 r284471 - /team/jpeeler/feature14882/main/
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Tue Aug 31 18:28:39 CDT 2010
Author: jpeeler
Date: Tue Aug 31 18:28:36 2010
New Revision: 284471
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=284471
Log:
add a callback instead of iterating manually and some other minor changes
Modified:
team/jpeeler/feature14882/main/features.c
Modified: team/jpeeler/feature14882/main/features.c
URL: http://svnview.digium.com/svn/asterisk/team/jpeeler/feature14882/main/features.c?view=diff&rev=284471&r1=284470&r2=284471
==============================================================================
--- team/jpeeler/feature14882/main/features.c (original)
+++ team/jpeeler/feature14882/main/features.c Tue Aug 31 18:28:36 2010
@@ -289,6 +289,7 @@
***/
#define DEFAULT_PARK_TIME 45000
+#define DEFAULT_PARK_EXTENSION "700"
#define DEFAULT_TRANSFER_DIGIT_TIMEOUT 3000
#define DEFAULT_FEATURE_DIGIT_TIMEOUT 1000
#define DEFAULT_NOANSWER_TIMEOUT_ATTENDED_TRANSFER 15000
@@ -442,6 +443,18 @@
struct ast_parkinglot *find_parkinglot(const char *name);
static struct ast_parkinglot *create_parkinglot(const char *name);
static struct ast_parkinglot *copy_parkinglot(const char *name, const struct ast_parkinglot *parkinglot);
+
+static int find_parkinglot_by_position_cb(void *obj, void *args, int flags)
+{
+ struct ast_parkinglot *parkinglot = obj;
+ int *parkpos = args;
+
+ if (*parkpos >= parkinglot->parking_start && *parkpos <= parkinglot->parking_stop) {
+ return CMP_MATCH | CMP_STOP;
+ }
+
+ return 0;
+}
static int find_parkinglot_by_exten_cb(void *obj, void *args, int flags)
{
@@ -4009,21 +4022,13 @@
struct ast_context *con;
int park = 0;
struct ast_bridge_config config;
- struct ao2_iterator iter;
- struct ast_parkinglot* parkinglot;
+ struct ast_parkinglot *parkinglot;
if (data) {
park = atoi((char *) data); /* char to int */
}
- iter = ao2_iterator_init(parkinglots, 0); /* searching for the proper parkinglot */
- while ((parkinglot = ao2_iterator_next(&iter))) {
- ao2_ref(parkinglot, -1);
- if (park >= parkinglot->parking_start && park <= parkinglot->parking_stop) { /* found parkinglot */
- break;
- }
- }
-
+ parkinglot = ao2_callback(parkinglots, 0, find_parkinglot_by_position_cb, (void *) &park);
if (!parkinglot)
parkinglot = default_parkinglot;
@@ -4334,10 +4339,9 @@
if (parkinglot->parkingtime == 0) {
parkinglot->parkingtime = DEFAULT_PARK_TIME;
}
- /* if there's no parkext specified - set to default */
if (ast_strlen_zero(parkinglot->parkext)) {
- ast_debug(2, "no parkext specified for %s - setting it to %s\n", parkinglot->name, "700");
- ast_copy_string(parkinglot->parkext, "700", sizeof(parkinglot->parkext));
+ ast_debug(2, "no parkext specified for %s - setting it to %s\n", parkinglot->name, DEFAULT_PARK_EXTENSION);
+ ast_copy_string(parkinglot->parkext, DEFAULT_PARK_EXTENSION, sizeof(parkinglot->parkext));
}
if (!var) { /* Default parking lot */
@@ -4420,7 +4424,7 @@
default_parkinglot = build_parkinglot(DEFAULT_PARKINGLOT, NULL);
if (default_parkinglot) {
ao2_lock(default_parkinglot);
- ast_copy_string(default_parkinglot->parkext,"700",sizeof(default_parkinglot->parkext));
+ ast_copy_string(default_parkinglot->parkext, DEFAULT_PARK_EXTENSION, sizeof(default_parkinglot->parkext));
default_parkinglot->parking_start = 701;
default_parkinglot->parking_stop = 750;
default_parkinglot->parking_offset = 0;
@@ -4437,7 +4441,7 @@
}
/* Reset to defaults */
- strcpy(default_parkinglot->parkext,"700");
+ strcpy(default_parkinglot->parkext, DEFAULT_PARK_EXTENSION);
strcpy(pickup_ext, "*8");
courtesytone[0] = '\0';
strcpy(xfersound, "beep");
@@ -4683,8 +4687,8 @@
while ((ctg = ast_category_browse(cfg, ctg))) {
/* Is this a parkinglot definition ? */
if (!strncasecmp(ctg, "parkinglot_", strlen("parkinglot_"))) {
- ast_debug(2, "Found configuration section %s, assume parking context\n", ctg);
- if(!build_parkinglot(ctg, ast_variable_browse(cfg, ctg))) /* Build a new parkinglot */
+ ast_debug(2, "Found configuration section %s, assume parking context\n", ctg);
+ if(!build_parkinglot(ctg, ast_variable_browse(cfg, ctg)))
ast_log(LOG_ERROR, "Could not build parking lot %s. Configuration error.\n", ctg);
else
ast_debug(1, "Configured parking context %s\n", ctg);
@@ -4726,11 +4730,11 @@
ast_log(LOG_ERROR, "Parking context '%s' does not exist and unable to create\n", default_parkinglot->parking_con);
return -1;
}
- res = ast_add_extension2(con, 1, default_parkinglot->parkext, 1, NULL, NULL, parkcall, NULL, NULL, registrar);
+ res = ast_add_extension2(con, 1, DEFAULT_PARK_EXTENSION, 1, NULL, NULL, parkcall, NULL, NULL, registrar);
if (default_parkinglot->parkaddhints)
park_add_hints(default_parkinglot->parking_con, default_parkinglot->parking_start, default_parkinglot->parking_stop);
if (!res)
- notify_metermaids(default_parkinglot->parkext, default_parkinglot->parking_con, AST_DEVICE_INUSE);
+ notify_metermaids(DEFAULT_PARK_EXTENSION, default_parkinglot->parking_con, AST_DEVICE_INUSE);
return res;
}
@@ -5625,4 +5629,3 @@
return res;
}
-
More information about the asterisk-commits
mailing list