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; }
static void manager_park_unbridged(struct mansession *s, const struct message *m, struct ast_channel *chan, const char *parkinglot, int timeout_override) { struct ast_bridge *parking_bridge = park_common_setup(chan, chan, parkinglot, NULL, 0, 0, timeout_override, 1); if (!parking_bridge) { astman_send_error(s, m, "Park action failed\n"); return; } if (ast_bridge_add_channel(parking_bridge, chan, NULL, 0, NULL)) { astman_send_error(s, m, "Park action failed\n"); ao2_cleanup(parking_bridge); return; } astman_send_ack(s, m, "Park successful\n"); ao2_cleanup(parking_bridge); }
/*! * \brief Bridge channels together * \param s * \param m * * Make sure valid channels were specified, * send errors if any of the channels could not be found/locked, answer channels if needed, * create the placeholder channels and grab the other channels * make the channels compatible, send error if we fail doing so * setup the bridge thread object and start the bridge. * * \retval 0 */ static int action_bridge(struct mansession *s, const struct message *m) { const char *channela = astman_get_header(m, "Channel1"); const char *channelb = astman_get_header(m, "Channel2"); enum play_tone_action playtone = parse_playtone(astman_get_header(m, "Tone")); RAII_VAR(struct ast_channel *, chana, NULL, ao2_cleanup); RAII_VAR(struct ast_channel *, chanb, NULL, ao2_cleanup); const char *chana_exten; const char *chana_context; int chana_priority; const char *chanb_exten; const char *chanb_context; int chanb_priority; struct ast_bridge *bridge; char buf[256]; RAII_VAR(struct ast_features_xfer_config *, xfer_cfg_a, NULL, ao2_cleanup); RAII_VAR(struct ast_features_xfer_config *, xfer_cfg_b, NULL, ao2_cleanup); /* make sure valid channels were specified */ if (ast_strlen_zero(channela) || ast_strlen_zero(channelb)) { astman_send_error(s, m, "Missing channel parameter in request"); return 0; } ast_debug(1, "Performing Bridge action on %s and %s\n", channela, channelb); /* Start with chana */ chana = ast_channel_get_by_name_prefix(channela, strlen(channela)); if (!chana) { snprintf(buf, sizeof(buf), "Channel1 does not exist: %s", channela); astman_send_error(s, m, buf); return 0; } ast_channel_lock(chana); xfer_cfg_a = ast_get_chan_features_xfer_config(chana); chana_exten = ast_strdupa(ast_channel_exten(chana)); chana_context = ast_strdupa(ast_channel_context(chana)); chana_priority = ast_channel_priority(chana); if (!ast_test_flag(ast_channel_flags(chana), AST_FLAG_IN_AUTOLOOP)) { chana_priority++; } ast_channel_unlock(chana); chanb = ast_channel_get_by_name_prefix(channelb, strlen(channelb)); if (!chanb) { snprintf(buf, sizeof(buf), "Channel2 does not exist: %s", channelb); astman_send_error(s, m, buf); return 0; } ast_channel_lock(chanb); xfer_cfg_b = ast_get_chan_features_xfer_config(chanb); chanb_exten = ast_strdupa(ast_channel_exten(chanb)); chanb_context = ast_strdupa(ast_channel_context(chanb)); chanb_priority = ast_channel_priority(chanb); if (!ast_test_flag(ast_channel_flags(chanb), AST_FLAG_IN_AUTOLOOP)) { chanb_priority++; } ast_channel_unlock(chanb); bridge = ast_bridge_basic_new(); if (!bridge) { astman_send_error(s, m, "Unable to create bridge\n"); return 0; } ast_bridge_set_after_go_on(chana, chana_context, chana_exten, chana_priority, NULL); if (ast_bridge_add_channel(bridge, chana, NULL, playtone & PLAYTONE_CHANNEL1, xfer_cfg_a ? xfer_cfg_a->xfersound : NULL)) { snprintf(buf, sizeof(buf), "Unable to add Channel1 to bridge: %s", ast_channel_name(chana)); astman_send_error(s, m, buf); ast_bridge_destroy(bridge, 0); return 0; } ast_bridge_set_after_go_on(chanb, chanb_context, chanb_exten, chanb_priority, NULL); if (ast_bridge_add_channel(bridge, chanb, NULL, playtone & PLAYTONE_CHANNEL2, xfer_cfg_b ? xfer_cfg_b->xfersound : NULL)) { snprintf(buf, sizeof(buf), "Unable to add Channel2 to bridge: %s", ast_channel_name(chanb)); astman_send_error(s, m, buf); ast_bridge_destroy(bridge, 0); return 0; } astman_send_ack(s, m, "Channels have been bridged"); ao2_cleanup(bridge); return 0; }