From 854c4c64fe2851312b1e13857dcd18e743e07594 Mon Sep 17 00:00:00 2001 From: Jonathan Rose Date: Tue, 25 Jun 2013 22:28:22 +0000 Subject: res_parking: Add Parking manager action to the new parking system (closes issue ASTERISK-21641) Reported by: Matt Jordan Review: https://reviewboard.asterisk.org/r/2573/ git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@392915 65c4cc65-6c06-0410-ace0-fbb531ad65f3 --- res/parking/parking_manager.c | 89 +++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 86 insertions(+), 3 deletions(-) (limited to 'res/parking/parking_manager.c') diff --git a/res/parking/parking_manager.c b/res/parking/parking_manager.c index 444c5a54f..5a2b3f6fd 100644 --- a/res/parking/parking_manager.c +++ b/res/parking/parking_manager.c @@ -37,6 +37,7 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$") #include "asterisk/astobj2.h" #include "asterisk/features.h" #include "asterisk/manager.h" +#include "asterisk/bridging.h" /*** DOCUMENTATION @@ -64,6 +65,33 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$") List parked calls. + + + Park a channel. + + + + + Channel name to park. + + + Channel name to use when constructing the dial string that will be dialed if the parked channel times out. + + + Overrides the timeout of the parking lot for this park action. Specified in milliseconds, but will be converted to + seconds. Use a value of 0 to nullify the timeout. + + + + The parking lot to use when parking the channel + + + + Park an arbitrary channel with optional arguments for specifying the parking lot used, how long + the channel should remain parked, and what dial string to use as the parker if the call times out. + + + Raised when a channel is parked. @@ -498,6 +526,61 @@ static int manager_parking_lot_list(struct mansession *s, const struct message * return RESULT_SUCCESS; } +static int manager_park(struct mansession *s, const struct message *m) +{ + const char *channel = astman_get_header(m, "Channel"); + const char *timeout_channel = S_OR(astman_get_header(m, "TimeoutChannel"), astman_get_header(m, "Channel2")); + const char *timeout = astman_get_header(m, "Timeout"); + const char *parkinglot = astman_get_header(m, "Parkinglot"); + char buf[BUFSIZ]; + int timeout_override = -1; + + RAII_VAR(struct ast_channel *, chan, NULL, ao2_cleanup); + RAII_VAR(struct ast_bridge *, parking_bridge, NULL, ao2_cleanup); + + if (ast_strlen_zero(channel)) { + astman_send_error(s, m, "Channel not specified"); + return 0; + } + + if (!ast_strlen_zero(timeout)) { + if (sscanf(timeout, "%30d", &timeout_override) != 1 || timeout < 0) { + astman_send_error(s, m, "Invalid Timeout value."); + return 0; + } + + if (timeout_override > 0) { + /* If greater than zero, convert to seconds for internal use. Must be >= 1 second. */ + timeout_override = MAX(1, timeout_override / 1000); + } + } + + if (!(chan = ast_channel_get_by_name(channel))) { + snprintf(buf, sizeof(buf), "Channel does not exist: %s", channel); + astman_send_error(s, m, buf); + return 0; + } + + ast_channel_lock(chan); + if (!ast_strlen_zero(timeout_channel)) { + pbx_builtin_setvar_helper(chan, "BLINDTRANSFER", timeout_channel); + } + ast_channel_unlock(chan); + + if (!(parking_bridge = park_common_setup(chan, chan, parkinglot, NULL, 0, 0, timeout_override, 0))) { + astman_send_error(s, m, "Park action failed\n"); + return 0; + } + + if (ast_bridge_add_channel(parking_bridge, chan, NULL, 0, NULL)) { + astman_send_error(s, m, "Park action failed\n"); + return 0; + } + + astman_send_ack(s, m, "Park successful\n"); + return 0; +} + void publish_parked_call_failure(struct ast_channel *parkee) { RAII_VAR(struct ast_parked_call_payload *, payload, NULL, ao2_cleanup); @@ -588,9 +671,9 @@ int load_parking_manager(void) { int res; - res = ast_manager_register_xml_core("Parkinglots", 0, manager_parking_lot_list); - res |= ast_manager_register_xml_core("ParkedCalls", 0, manager_parking_status); - /* TODO Add a 'Park' manager action */ + res = ast_manager_register_xml_core("Parkinglots", EVENT_FLAG_CALL, manager_parking_lot_list); + res |= ast_manager_register_xml_core("ParkedCalls", EVENT_FLAG_CALL, manager_parking_status); + res |= ast_manager_register_xml_core("Park", EVENT_FLAG_CALL, manager_park); parking_manager_enable_stasis(); return res ? -1 : 0; } -- cgit v1.2.3