2 * Asterisk -- An open source telephony toolkit.
4 * Copyright (C) 2013, Digium, Inc.
6 * Jonathan Rose <jrose@digium.com>
8 * See http://www.asterisk.org for more information about
9 * the Asterisk project. Please do not directly contact
10 * any of the maintainers of this project for assistance;
11 * the project provides a web site, mailing lists and IRC
12 * channels for your use.
14 * This program is free software, distributed under the terms of
15 * the GNU General Public License Version 2. See the LICENSE file
16 * at the top of the source tree.
23 * \author Jonathan Rose <jrose@digium.com>
28 ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
30 #include "asterisk/_private.h"
31 #include "asterisk/astobj2.h"
32 #include "asterisk/pbx.h"
33 #include "asterisk/bridging.h"
34 #include "asterisk/parking.h"
35 #include "asterisk/channel.h"
36 #include "asterisk/_private.h"
38 /*! \brief Message type for parked calls */
39 STASIS_MESSAGE_TYPE_DEFN(ast_parked_call_type);
41 /*! \brief Topic for parking lots */
42 static struct stasis_topic *parking_topic;
44 /*! \brief Function Callback for handling blind transfers to park applications */
45 static ast_park_blind_xfer_fn ast_park_blind_xfer_func = NULL;
47 /*! \brief Function Callback for handling a bridge channel trying to park itself */
48 static ast_bridge_channel_park_fn ast_bridge_channel_park_func = NULL;
50 static void parking_stasis_cleanup(void)
52 STASIS_MESSAGE_TYPE_CLEANUP(ast_parked_call_type);
53 ao2_cleanup(parking_topic);
57 int ast_parking_stasis_init(void)
59 if (STASIS_MESSAGE_TYPE_INIT(ast_parked_call_type)) {
63 parking_topic = stasis_topic_create("ast_parking");
67 ast_register_cleanup(parking_stasis_cleanup);
71 struct stasis_topic *ast_parking_topic(void)
76 /*! \brief Destructor for parked_call_payload objects */
77 static void parked_call_payload_destructor(void *obj)
79 struct ast_parked_call_payload *park_obj = obj;
81 ao2_cleanup(park_obj->parkee);
82 ao2_cleanup(park_obj->parker);
83 ast_string_field_free_memory(park_obj);
86 struct ast_parked_call_payload *ast_parked_call_payload_create(enum ast_parked_call_event_type event_type,
87 struct ast_channel_snapshot *parkee_snapshot, struct ast_channel_snapshot *parker_snapshot,
88 struct ast_channel_snapshot *retriever_snapshot, const char *parkinglot,
89 unsigned int parkingspace, unsigned long int timeout,
90 unsigned long int duration)
92 RAII_VAR(struct ast_parked_call_payload *, payload, NULL, ao2_cleanup);
94 payload = ao2_alloc(sizeof(*payload), parked_call_payload_destructor);
99 if (ast_string_field_init(payload, 32)) {
103 payload->event_type = event_type;
105 ao2_ref(parkee_snapshot, +1);
106 payload->parkee = parkee_snapshot;
108 if (parker_snapshot) {
109 ao2_ref(parker_snapshot, +1);
110 payload->parker = parker_snapshot;
113 if (retriever_snapshot) {
114 ao2_ref(retriever_snapshot, +1);
115 payload->retriever = retriever_snapshot;
119 ast_string_field_set(payload, parkinglot, parkinglot);
122 payload->parkingspace = parkingspace;
123 payload->timeout = timeout;
124 payload->duration = duration;
126 /* Bump the ref count by one since RAII_VAR is going to eat one when we leave. */
127 ao2_ref(payload, +1);
131 void ast_install_park_blind_xfer_func(ast_park_blind_xfer_fn park_blind_xfer_func)
133 ast_park_blind_xfer_func = park_blind_xfer_func;
136 void ast_install_bridge_channel_park_func(ast_bridge_channel_park_fn bridge_channel_park_func)
138 ast_bridge_channel_park_func = bridge_channel_park_func;
141 void ast_uninstall_park_blind_xfer_func(void)
143 ast_park_blind_xfer_func = NULL;
146 void ast_uninstall_bridge_channel_park_func(void)
148 ast_bridge_channel_park_func = NULL;
151 int ast_park_blind_xfer(struct ast_bridge *bridge, struct ast_bridge_channel *parker,
152 struct ast_exten *park_exten)
154 static int warned = 0;
155 if (ast_park_blind_xfer_func) {
156 return ast_park_blind_xfer_func(bridge, parker, park_exten);
159 if (warned++ % 10 == 0) {
160 ast_verb(3, "%s attempted to blind transfer to a parking extension, but no parking blind transfer function is loaded.\n",
161 ast_channel_name(parker->chan));
167 struct ast_exten *ast_get_parking_exten(const char *exten_str, struct ast_channel *chan, const char *context)
169 struct ast_exten *exten;
170 struct pbx_find_info q = { .stacklen = 0 }; /* the rest is reset in pbx_find_extension */
171 const char *app_at_exten;
173 ast_debug(4, "Checking if %s@%s is a parking exten\n", exten_str, context);
174 exten = pbx_find_extension(chan, NULL, &q, context, exten_str, 1, NULL, NULL,
180 app_at_exten = ast_get_extension_app(exten);
181 if (!app_at_exten || strcasecmp(PARK_APPLICATION, app_at_exten)) {
188 void ast_bridge_channel_park(struct ast_bridge_channel *bridge_channel, const char *parkee_uuid, const char *parker_uuid, const char *app_data)
190 /* Run installable function */
191 if (ast_bridge_channel_park_func) {
192 return ast_bridge_channel_park_func(bridge_channel, parkee_uuid, parker_uuid, app_data);