[asterisk-commits] jpeeler: branch jpeeler/feature14882 r279980 - /team/jpeeler/feature14882/main/
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Tue Jul 27 16:23:18 CDT 2010
Author: jpeeler
Date: Tue Jul 27 16:23:14 2010
New Revision: 279980
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=279980
Log:
Commit current work to at least make patch compile
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=279980&r1=279979&r2=279980
==============================================================================
--- team/jpeeler/feature14882/main/features.c (original)
+++ team/jpeeler/feature14882/main/features.c Tue Jul 27 16:23:14 2010
@@ -345,6 +345,7 @@
/*! \brief Structure for parking lots which are put in a container. */
struct ast_parkinglot {
char name[AST_MAX_CONTEXT];
+ char parkext[AST_MAX_CONTEXT]; /*!< Parkingextension */
char parking_con[AST_MAX_EXTENSION]; /*!< Context for which parking is made accessible */
char parking_con_dial[AST_MAX_EXTENSION]; /*!< Context for dialback for parking (KLUDGE) */
int parking_start; /*!< First available extension for parking */
@@ -694,20 +695,22 @@
struct parkeduser *pu;
};
-static struct parkeduser *park_space_reserve(struct ast_channel *chan, struct ast_channel *peer, struct ast_park_call_args *args)
+static struct parkeduser *park_space_reserve(struct ast_channel *chan, struct ast_channel *peer, struct ast_park_call_args *args, struct ast_parkinglot *parkinglot)
{
struct parkeduser *pu;
int i, parking_space = -1, parking_range;
const char *parkinglotname = NULL;
const char *parkingexten;
- struct ast_parkinglot *parkinglot = NULL;
-
- if (peer)
+
+ if (parkinglot) {
+ parkinglotname = parkinglot->name;
+ } else if (peer) {
parkinglotname = findparkinglotname(peer);
- else /* peer was NULL, check chan (ParkAndAnnounce / res_agi) */
+ } else { /* peer was NULL, check chan (ParkAndAnnounce / res_agi) */
parkinglotname = findparkinglotname(chan);
-
- if (parkinglotname) {
+ }
+
+ if (!parkinglot && parkinglotname) {
ast_debug(1, "Found chanvar Parkinglot: %s\n", parkinglotname);
parkinglot = find_parkinglot(parkinglotname);
@@ -860,7 +863,7 @@
const char *event_from;
if (pu == NULL)
- args->pu = pu = park_space_reserve(chan, peer, args);
+ args->pu = pu = park_space_reserve(chan, peer, args, NULL);
if (pu == NULL)
return 1; /* Continue execution if possible */
@@ -1011,22 +1014,26 @@
return park_call_full(chan, peer, &args);
}
-static int masq_park_call(struct ast_channel *rchan, struct ast_channel *peer, int timeout, int *extout, int play_announcement, struct ast_park_call_args *args)
+static int masq_park_call(struct ast_channel *rchan, struct ast_channel *peer, int timeout, int *extout, int play_announcement, struct ast_park_call_args *args, struct ast_parkinglot *parkinglot)
{
struct ast_channel *chan;
struct ast_frame *f;
int park_status;
struct ast_park_call_args park_args = {0,};
+ /* transferee = rchan */
+ /* transferer = peer */
+
if (!args) {
args = &park_args;
args->timeout = timeout;
args->extout = extout;
}
- if ((args->pu = park_space_reserve(rchan, peer, args)) == NULL) {
- if (peer)
+ if ((args->pu = park_space_reserve(peer, rchan, args, parkinglot)) == NULL) { /* create parkinglot */
+ if (peer){ /* if error */
ast_stream_and_wait(peer, "beeperr", "");
+ }
return AST_FEATURE_RETURN_PARKFAILED;
}
@@ -1040,6 +1047,7 @@
chan->readformat = rchan->readformat;
chan->writeformat = rchan->writeformat;
ast_channel_masquerade(chan, rchan);
+ ast_string_field_set(chan,parkinglot,rchan->parkinglot); /* set the parkinglot */
/* Setup the extensions and such */
set_c_e_p(chan, rchan->context, rchan->exten, rchan->priority);
@@ -1060,7 +1068,9 @@
if (peer && (!play_announcement && args == &park_args)) {
args->orig_chan_name = ast_strdupa(peer->name);
}
-
+ /* park call */
+ /* chan = transferee */
+ /* peer = transferer */
park_status = park_call_full(chan, peer, args);
if (park_status == 1) {
/* would be nice to play "invalid parking extension" */
@@ -1074,17 +1084,17 @@
/* Park call via masqueraded channel */
int ast_masq_park_call(struct ast_channel *rchan, struct ast_channel *peer, int timeout, int *extout)
{
- return masq_park_call(rchan, peer, timeout, extout, 0, NULL);
-}
-
-static int masq_park_call_announce_args(struct ast_channel *rchan, struct ast_channel *peer, struct ast_park_call_args *args)
-{
- return masq_park_call(rchan, peer, 0, NULL, 1, args);
-}
-
-static int masq_park_call_announce(struct ast_channel *rchan, struct ast_channel *peer, int timeout, int *extout)
-{
- return masq_park_call(rchan, peer, timeout, extout, 1, NULL);
+ return masq_park_call(rchan, peer, timeout, extout, 0, NULL, NULL);
+}
+
+static int masq_park_call_announce_args(struct ast_channel *rchan, struct ast_channel *peer, struct ast_park_call_args *args, struct ast_parkinglot *parkinglot)
+{
+ return masq_park_call(rchan, peer, 0, NULL, 1, args, NULL);
+}
+
+static int masq_park_call_announce(struct ast_channel *rchan, struct ast_channel *peer, int timeout, int *extout, struct ast_parkinglot *parkinglot)
+{
+ return masq_park_call(rchan, peer, timeout, extout, 1, NULL, parkinglot);
}
#ifdef TEST_FRAMEWORK
@@ -1290,6 +1300,13 @@
struct ast_channel *parker;
struct ast_channel *parkee;
int res = 0;
+ struct ast_parkinglot* parkinglot = NULL;
+
+ if (data){
+ parkinglot = (struct ast_parkinglot *) data;
+ if (option_debug)
+ ast_log(LOG_NOTICE, "Parkinglot specified for builtin_parkcall: %s\n", parkinglot->name);
+ }
set_peers(&parker, &parkee, peer, chan, sense);
/* we used to set chan's exten and priority to "s" and 1
@@ -1306,7 +1323,7 @@
res = ast_safe_sleep(chan, 1000);
if (!res) { /* one direction used to call park_call.... */
- res = masq_park_call_announce(parkee, parker, 0, NULL);
+ res = masq_park_call_announce(parkee, parker, 0, NULL, parkinglot);
/* PBX should hangup zombie channel if a masquerade actually occurred (res=0) */
}
@@ -1620,8 +1637,11 @@
struct ast_channel *transferer;
struct ast_channel *transferee;
const char *transferer_real_context;
+ struct ao2_iterator iter;
+ struct ast_parkinglot *parkinglot = NULL;
char xferto[256];
int res, parkstatus = 0;
+ int xferto_valid = 0;
set_peers(&transferer, &transferee, peer, chan, sense);
transferer_real_context = real_ctx(transferer, transferee);
@@ -1647,11 +1667,22 @@
finishup(transferee);
return res;
}
- if (!strcmp(xferto, ast_parking_ext())) {
+
+ /* check whether xferto is a valid parking extension in parkinglots or not */
+ iter = ao2_iterator_init(parkinglots, 0);
+ while ((parkinglot = ao2_iterator_next(&iter))) {
+ if (!strcmp(xferto,parkinglot->parkext)) {
+ xferto_valid = 1;
+ break; /* found it */
+ }
+ ao2_ref(parkinglot, -1);
+ }
+
+ if (xferto_valid) {
res = finishup(transferee);
if (res)
res = -1;
- else if (!(parkstatus = masq_park_call_announce(transferee, transferer, 0, NULL))) { /* success */
+ else if (!(parkstatus = masq_park_call_announce(transferee, transferer, 0, NULL, parkinglot))) { /* success */
/* We return non-zero, but tell the PBX not to hang the channel when
the thread dies -- We have to be careful now though. We are responsible for
hanging up the channel, else it will never be hung up! */
@@ -1706,7 +1737,7 @@
} else {
ast_verb(3, "Unable to find extension '%s' in context '%s'\n", xferto, transferer_real_context);
}
- if (parkstatus != AST_FEATURE_RETURN_PARKFAILED && ast_stream_and_wait(transferer, xferfailsound, AST_DIGIT_ANY) < 0) {
+ if (parkstatus != AST_FEATURE_RETURN_PARKFAILED && ast_stream_and_wait(transferer, xferfailsound, AST_DIGIT_ANY) < 0) { /* Play 'extension does not exist' */
finishup(transferee);
return -1;
}
@@ -1769,6 +1800,8 @@
struct ast_party_connected_line connected_line;
struct ast_datastore *features_datastore;
struct ast_dial_features *dialfeatures = NULL;
+ struct ao2_iterator iter;
+ struct ast_parkinglot *parkinglot;
ast_debug(1, "Executing Attended Transfer %s, %s (sense=%d) \n", chan->name, peer->name, sense);
set_peers(&transferer, &transferee, peer, chan, sense);
@@ -1811,12 +1844,21 @@
return AST_FEATURE_RETURN_SUCCESS;
}
- /* If we are attended transfering to parking, just use builtin_parkcall instead of trying to track all of
- * the different variables for handling this properly with a builtin_atxfer */
- if (!strcmp(xferto, ast_parking_ext())) {
- finishup(transferee);
- return builtin_parkcall(chan, peer, config, code, sense, data);
- }
+ /* If we are attended transfering to parking, just use builtin_parkcall instead of trying to track all of
+ * the different variables for handling this properly with a builtin_atxfer */
+
+ /* if there are more possible parkingextensions to choose from, you need to figure out the proper parkinglot
+ * and pass it to builtin_parkcall */
+
+ iter = ao2_iterator_init(parkinglots, 0);
+ while ((parkinglot = ao2_iterator_next(&iter))) { /* look for all parkinglots */
+ if (!strcmp(xferto, parkinglot->parkext)) {
+ finishup(transferee);
+ data = (void *)parkinglot;
+ return builtin_parkcall(chan, peer, config, code, sense, data);
+ }
+ ao2_ref(parkinglot, -1);
+ }
l = strlen(xferto);
snprintf(xferto + l, sizeof(xferto) - l, "@%s/n", transferer_real_context); /* append context */
@@ -3824,20 +3866,24 @@
/*! \brief Find parkinglot by name */
struct ast_parkinglot *find_parkinglot(const char *name)
{
- struct ast_parkinglot *parkinglot = NULL;
- struct ast_parkinglot tmp_parkinglot;
-
+
+ struct ao2_iterator iter;
+ struct ast_parkinglot *parkinglot;
+
if (ast_strlen_zero(name))
return NULL;
- ast_copy_string(tmp_parkinglot.name, name, sizeof(tmp_parkinglot.name));
-
- parkinglot = ao2_find(parkinglots, &tmp_parkinglot, OBJ_POINTER);
-
- if (parkinglot && option_debug)
- ast_log(LOG_DEBUG, "Found Parkinglot: %s\n", parkinglot->name);
-
- return parkinglot;
+ iter = ao2_iterator_init(parkinglots,0);
+
+ while ((parkinglot = ao2_iterator_next(&iter))) {
+ if (!strncasecmp(parkinglot->name,name,sizeof(parkinglot->parking_con))){
+ if (option_debug){
+ ast_log(LOG_DEBUG, "Found Parkinglot: %s\n", parkinglot->name);
+ }
+ return parkinglot;
+ }
+ }
+ return NULL;
}
/*! \brief Copy parkinglot and store it with new name */
@@ -3939,7 +3985,7 @@
ast_app_parse_options(park_call_options, &flags, NULL, app_args.options);
args.flags = flags.flags;
- res = masq_park_call_announce_args(chan, chan, &args);
+ res = masq_park_call_announce_args(chan, chan, &args, NULL);
/* Continue on in the dialplan */
if (res == 1) {
ast_copy_string(chan->exten, orig_exten, sizeof(chan->exten));
@@ -3954,7 +4000,7 @@
}
/*! \brief Pickup parked call */
-static int park_exec_full(struct ast_channel *chan, const char *data, struct ast_parkinglot *parkinglot)
+static int park_exec_full(struct ast_channel *chan, const char *data)
{
int res = 0;
struct ast_channel *peer=NULL;
@@ -3962,11 +4008,21 @@
struct ast_context *con;
int park = 0;
struct ast_bridge_config config;
-
- if (data)
- park = atoi((char *) data);
-
- parkinglot = find_parkinglot(findparkinglotname(chan));
+ struct ao2_iterator iter;
+ 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;
+ }
+ }
+
if (!parkinglot)
parkinglot = default_parkinglot;
@@ -4124,7 +4180,7 @@
static int park_exec(struct ast_channel *chan, const char *data)
{
- return park_exec_full(chan, data, default_parkinglot);
+ return park_exec_full(chan, data);
}
/*! \brief Unreference parkinglot object. If no more references,
@@ -4173,6 +4229,25 @@
ao2_unlink(parkinglots, ruin);
}
+/*!
+ * \brief Add parking hints for all defined parking lots
+ * \param context
+ * \param start starting parkinglot number
+ * \param stop ending parkinglot number
+*/
+static void park_add_hints(char *context, int start, int stop)
+{
+ int numext;
+ char device[AST_MAX_EXTENSION];
+ char exten[10];
+
+ for (numext = start; numext <= stop; numext++) {
+ snprintf(exten, sizeof(exten), "%d", numext);
+ snprintf(device, sizeof(device), "park:%s@%s", exten, context);
+ ast_add_extension(context, 1, exten, PRIORITY_HINT, NULL, NULL, device, NULL, NULL, registrar);
+ }
+}
+
/*! \brief Build parkinglot from configuration and chain it in */
static struct ast_parkinglot *build_parkinglot(char *name, struct ast_variable *var)
{
@@ -4201,6 +4276,8 @@
while(confvar) {
if (!strcasecmp(confvar->name, "context")) {
ast_copy_string(parkinglot->parking_con, confvar->value, sizeof(parkinglot->parking_con));
+ } else if (!strcasecmp(confvar->name, "parkext")) {
+ ast_copy_string(parkinglot->parkext, confvar->value, sizeof(parkinglot->parkext));
} else if (!strcasecmp(confvar->name, "parkingtime")) {
if ((sscanf(confvar->value, "%30d", &parkinglot->parkingtime) != 1) || (parkinglot->parkingtime < 1)) {
ast_log(LOG_WARNING, "%s is not a valid parkingtime\n", confvar->value);
@@ -4256,6 +4333,11 @@
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_log(LOG_NOTICE,"no parkext specified for %s - setting it to %s\n",parkinglot->name, "700");
+ ast_copy_string(parkinglot->parkext,"700",sizeof(parkinglot->parkext));
+ }
if (!var) { /* Default parking lot */
ast_copy_string(parkinglot->parking_con, "parkedcalls", sizeof(parkinglot->parking_con));
@@ -4277,11 +4359,15 @@
/* Add a parking extension into the context */
if (!error && !oldparkinglot) {
- if (!ast_strlen_zero(ast_parking_ext())) {
- if (ast_add_extension2(con, 1, ast_parking_ext(), 1, NULL, NULL, parkcall, strdup(""), ast_free_ptr, registrar) == -1)
+ if (!ast_strlen_zero(parkinglot->parkext)) {
+ if (ast_add_extension2(con, 1, parkinglot->parkext, 1, NULL, NULL, parkcall, strdup(""), ast_free_ptr, registrar) == -1)
error = 1;
}
}
+
+ /* Add parking hints */
+ if (parkinglot->parkaddhints)
+ park_add_hints(parkinglot->parking_con, parkinglot->parking_start, parkinglot->parking_stop);
ao2_unlock(parkinglot);
@@ -4303,25 +4389,6 @@
return parkinglot;
}
-
-/*!
- * \brief Add parking hints for all defined parking lots
- * \param context
- * \param start starting parkinglot number
- * \param stop ending parkinglot number
-*/
-static void park_add_hints(char *context, int start, int stop)
-{
- int numext;
- char device[AST_MAX_EXTENSION];
- char exten[10];
-
- for (numext = start; numext <= stop; numext++) {
- snprintf(exten, sizeof(exten), "%d", numext);
- snprintf(device, sizeof(device), "park:%s@%s", exten, context);
- ast_add_extension(context, 1, exten, PRIORITY_HINT, NULL, NULL, device, NULL, NULL, registrar);
- }
-}
static int load_config(void)
{
@@ -4333,8 +4400,6 @@
struct ast_variable *var = NULL;
struct feature_group *fg = NULL;
struct ast_flags config_flags = { 0 };
- char old_parking_ext[AST_MAX_EXTENSION];
- char old_parking_con[AST_MAX_EXTENSION] = "";
char *ctg;
static const char * const categories[] = {
/* Categories in features.conf that are not
@@ -4344,22 +4409,29 @@
"featuremap",
"applicationmap"
};
-
+ struct ao2_iterator iter;
+ struct ast_parkinglot *curlot;
+
+ /* delete existing parkinglots */
+ iter = ao2_iterator_init(parkinglots, 0);
+ while ((curlot = ao2_iterator_next(&iter))) {
+ parkinglot_destroy(curlot);
+ ao2_ref(curlot, -1);
+ }
+ default_parkinglot = NULL;
+
+ default_parkinglot = build_parkinglot(DEFAULT_PARKINGLOT, NULL);
if (default_parkinglot) {
- strcpy(old_parking_con, default_parkinglot->parking_con);
- strcpy(old_parking_ext, parking_ext);
- } else {
- default_parkinglot = build_parkinglot(DEFAULT_PARKINGLOT, NULL);
- if (default_parkinglot) {
- ao2_lock(default_parkinglot);
- default_parkinglot->parking_start = 701;
- default_parkinglot->parking_stop = 750;
- default_parkinglot->parking_offset = 0;
- default_parkinglot->parkfindnext = 0;
- default_parkinglot->parkingtime = DEFAULT_PARK_TIME;
- ao2_unlock(default_parkinglot);
- }
- }
+ ao2_lock(default_parkinglot);
+ ast_copy_string(default_parkinglot->parkext,"700",sizeof(default_parkinglot->parkext));
+ default_parkinglot->parking_start = 701;
+ default_parkinglot->parking_stop = 750;
+ default_parkinglot->parking_offset = 0;
+ default_parkinglot->parkfindnext = 0;
+ default_parkinglot->parkingtime = DEFAULT_PARK_TIME;
+ ao2_unlock(default_parkinglot);
+ }
+
if (default_parkinglot) {
if (option_debug)
ast_log(LOG_DEBUG, "Configuration of default parkinglot done.\n");
@@ -4367,10 +4439,9 @@
ast_log(LOG_ERROR, "Configuration of default parkinglot failed.\n");
return -1;
}
-
/* Reset to defaults */
- strcpy(parking_ext, "700");
+ strcpy(default_parkinglot->parkext,"700");
strcpy(pickup_ext, "*8");
courtesytone[0] = '\0';
strcpy(xfersound, "beep");
@@ -4401,7 +4472,7 @@
}
for (var = ast_variable_browse(cfg, "general"); var; var = var->next) {
if (!strcasecmp(var->name, "parkext")) {
- ast_copy_string(parking_ext, var->value, sizeof(parking_ext));
+ ast_copy_string(default_parkinglot->parkext, var->value, sizeof(default_parkinglot->parkext));
} else if (!strcasecmp(var->name, "context")) {
ast_copy_string(default_parkinglot->parking_con, var->value, sizeof(default_parkinglot->parking_con));
} else if (!strcasecmp(var->name, "parkingtime")) {
@@ -4616,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)))
+ 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_log(LOG_ERROR, "Could not build parking lot %s. Configuration error.\n", ctg);
else
ast_debug(1, "Configured parking context %s\n", ctg);
@@ -4655,22 +4726,15 @@
ast_config_destroy(cfg);
- /* Remove the old parking extension */
- if (!ast_strlen_zero(old_parking_con) && (con = ast_context_find(old_parking_con))) {
- if(ast_context_remove_extension2(con, old_parking_ext, 1, registrar, 0))
- notify_metermaids(old_parking_ext, old_parking_con, AST_DEVICE_NOT_INUSE);
- ast_debug(1, "Removed old parking extension %s@%s\n", old_parking_ext, old_parking_con);
- }
-
if (!(con = ast_context_find_or_create(NULL, NULL, default_parkinglot->parking_con, registrar))) {
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, ast_parking_ext(), 1, NULL, NULL, parkcall, NULL, NULL, registrar);
+ res = ast_add_extension2(con, 1, default_parkinglot->parkext, 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(ast_parking_ext(), default_parkinglot->parking_con, AST_DEVICE_INUSE);
+ notify_metermaids(default_parkinglot->parkext, default_parkinglot->parking_con, AST_DEVICE_INUSE);
return res;
}
@@ -4749,9 +4813,11 @@
while ((curlot = ao2_iterator_next(&iter))) {
ast_cli(a->fd, "\nCall parking (Parking lot: %s)\n", curlot->name);
ast_cli(a->fd, "------------\n");
- ast_cli(a->fd,"%-22s: %s\n", "Parking extension", parking_ext);
+ ast_cli(a->fd,"%-22s: %s\n", "Parking extension", curlot->parkext);
ast_cli(a->fd,"%-22s: %s\n", "Parking context", curlot->parking_con);
ast_cli(a->fd,"%-22s: %d-%d\n", "Parked call extensions", curlot->parking_start, curlot->parking_stop);
+ ast_cli(a->fd,"%-22s: %d\n", "Parkingtime", curlot->parkingtime);
+ ast_cli(a->fd,"%-22s: %s\n", "MusicOnHold class", curlot->mohclass);
ast_cli(a->fd,"\n");
ao2_ref(curlot, -1);
}
@@ -5563,3 +5629,4 @@
return res;
}
+
More information about the asterisk-commits
mailing list