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/bridge.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->retriever);
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, const char *parker_dial_string,
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 (retriever_snapshot) {
109 ao2_ref(retriever_snapshot, +1);
110 payload->retriever = retriever_snapshot;
114 ast_string_field_set(payload, parkinglot, parkinglot);
117 if (parker_dial_string) {
118 ast_string_field_set(payload, parker_dial_string, parker_dial_string);
121 payload->parkingspace = parkingspace;
122 payload->timeout = timeout;
123 payload->duration = duration;
125 /* Bump the ref count by one since RAII_VAR is going to eat one when we leave. */
126 ao2_ref(payload, +1);
130 void ast_install_park_blind_xfer_func(ast_park_blind_xfer_fn park_blind_xfer_func)
132 ast_park_blind_xfer_func = park_blind_xfer_func;
135 void ast_install_bridge_channel_park_func(ast_bridge_channel_park_fn bridge_channel_park_func)
137 ast_bridge_channel_park_func = bridge_channel_park_func;
140 void ast_uninstall_park_blind_xfer_func(void)
142 ast_park_blind_xfer_func = NULL;
145 void ast_uninstall_bridge_channel_park_func(void)
147 ast_bridge_channel_park_func = NULL;
150 int ast_park_blind_xfer(struct ast_bridge_channel *parker, struct ast_exten *park_exten)
152 static int warned = 0;
154 if (ast_park_blind_xfer_func) {
155 return ast_park_blind_xfer_func(parker, park_exten);
158 if (warned++ % 10 == 0) {
159 ast_verb(3, "%s attempted to blind transfer to a parking extension, but no parking blind transfer function is loaded.\n",
160 ast_channel_name(parker->chan));
166 struct ast_exten *ast_get_parking_exten(const char *exten_str, struct ast_channel *chan, const char *context)
168 struct ast_exten *exten;
169 struct pbx_find_info q = { .stacklen = 0 }; /* the rest is reset in pbx_find_extension */
170 const char *app_at_exten;
172 ast_debug(4, "Checking if %s@%s is a parking exten\n", exten_str, context);
173 exten = pbx_find_extension(chan, NULL, &q, context, exten_str, 1, NULL, NULL,
179 app_at_exten = ast_get_extension_app(exten);
180 if (!app_at_exten || strcasecmp(PARK_APPLICATION, app_at_exten)) {
187 void ast_bridge_channel_park(struct ast_bridge_channel *bridge_channel, const char *parkee_uuid, const char *parker_uuid, const char *app_data)
189 /* Run installable function */
190 if (ast_bridge_channel_park_func) {
191 return ast_bridge_channel_park_func(bridge_channel, parkee_uuid, parker_uuid, app_data);