2 * Asterisk -- An open source telephony toolkit.
4 * Copyright (C) 1999 - 2006, Digium, Inc.
6 * Mark Spencer <markster@digium.com>
8 * Author: Ben Miller <bgmiller@dccinc.com>
9 * With TONS of help from Mark!
11 * See http://www.asterisk.org for more information about
12 * the Asterisk project. Please do not directly contact
13 * any of the maintainers of this project for assistance;
14 * the project provides a web site, mailing lists and IRC
15 * channels for your use.
17 * This program is free software, distributed under the terms of
18 * the GNU General Public License Version 2. See the LICENSE file
19 * at the top of the source tree.
24 * \brief ParkAndAnnounce application for Asterisk
26 * \author Ben Miller <bgmiller@dccinc.com>
27 * \arg With TONS of help from Mark!
29 * \ingroup applications
34 ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
36 #include "asterisk/file.h"
37 #include "asterisk/channel.h"
38 #include "asterisk/pbx.h"
39 #include "asterisk/module.h"
40 #include "asterisk/features.h"
41 #include "asterisk/say.h"
42 #include "asterisk/lock.h"
43 #include "asterisk/utils.h"
44 #include "asterisk/app.h"
46 static char *app = "ParkAndAnnounce";
48 static char *synopsis = "Park and Announce";
50 static char *descrip =
51 " ParkAndAnnounce(announce:template,timeout,dial[,return_context]):\n"
52 "Park a call into the parkinglot and announce the call to another channel.\n"
54 "announce template: Colon-separated list of files to announce. The word PARKED\n"
55 " will be replaced by a say_digits of the extension in which\n"
56 " the call is parked.\n"
57 "timeout: Time in seconds before the call returns into the return\n"
59 "dial: The app_dial style resource to call to make the\n"
60 " announcement. Console/dsp calls the console.\n"
61 "return_context: The goto-style label to jump the call back into after\n"
62 " timeout. Default <priority+1>.\n"
64 "The variable ${PARKEDAT} will contain the parking extension into which the\n"
65 "call was placed. Use with the Local channel to allow the dialplan to make\n"
66 "use of this information.\n";
69 static int parkandannounce_exec(struct ast_channel *chan, void *data)
72 int lot, timeout = 0, dres;
73 char *dialtech, *tmp[100], buf[13];
77 struct ast_channel *dchan;
78 struct outgoing_helper oh = { 0, };
80 AST_DECLARE_APP_ARGS(args,
81 AST_APP_ARG(template);
84 AST_APP_ARG(return_context);
86 if (ast_strlen_zero(data)) {
87 ast_log(LOG_WARNING, "ParkAndAnnounce requires arguments: (announce:template|timeout|dial|[return_context])\n");
91 s = ast_strdupa(data);
92 AST_STANDARD_APP_ARGS(args, s);
95 timeout = atoi(args.timeout) * 1000;
97 if (ast_strlen_zero(args.dial)) {
98 ast_log(LOG_WARNING, "PARK: A dial resource must be specified i.e: Console/dsp or DAHDI/g1/5551212\n");
102 dialtech = strsep(&args.dial, "/");
103 ast_verb(3, "Dial Tech,String: (%s,%s)\n", dialtech, args.dial);
105 if (!ast_strlen_zero(args.return_context))
106 ast_parseable_goto(chan, args.return_context);
108 ast_verb(3, "Return Context: (%s,%s,%d) ID: %s\n", chan->context, chan->exten, chan->priority, chan->cid.cid_num);
109 if (!ast_exists_extension(chan, chan->context, chan->exten, chan->priority, chan->cid.cid_num)) {
110 ast_verb(3, "Warning: Return Context Invalid, call will return to default|s\n");
113 /* we are using masq_park here to protect * from touching the channel once we park it. If the channel comes out of timeout
114 before we are done announcing and the channel is messed with, Kablooeee. So we use Masq to prevent this. */
116 res = ast_masq_park_call(chan, NULL, timeout, &lot);
120 ast_verb(3, "Call Parking Called, lot: %d, timeout: %d, context: %s\n", lot, timeout, args.return_context);
122 /* Now place the call to the extension */
124 snprintf(buf, sizeof(buf), "%d", lot);
125 oh.parent_channel = chan;
126 oh.vars = ast_variable_new("_PARKEDAT", buf, "");
127 dchan = __ast_request_and_dial(dialtech, AST_FORMAT_SLINEAR, args.dial, 30000, &outstate, chan->cid.cid_num, chan->cid.cid_name, &oh);
130 if (dchan->_state == AST_STATE_UP) {
131 ast_verb(4, "Channel %s was answered.\n", dchan->name);
133 ast_verb(4, "Channel %s was never answered.\n", dchan->name);
134 ast_log(LOG_WARNING, "PARK: Channel %s was never answered for the announce.\n", dchan->name);
139 ast_log(LOG_WARNING, "PARK: Unable to allocate announce channel.\n");
143 ast_stopstream(dchan);
145 /* now we have the call placed and are ready to play stuff to it */
147 ast_verb(4, "Announce Template:%s\n", args.template);
149 for (looptemp = 0; looptemp < ARRAY_LEN(tmp); looptemp++) {
150 if ((tmp[looptemp] = strsep(&args.template, ":")) != NULL)
156 for (i = 0; i < looptemp; i++) {
157 ast_verb(4, "Announce:%s\n", tmp[i]);
158 if (!strcmp(tmp[i], "PARKED")) {
159 ast_say_digits(dchan, lot, "", dchan->language);
161 dres = ast_streamfile(dchan, tmp[i], dchan->language);
163 dres = ast_waitstream(dchan, "");
165 ast_log(LOG_WARNING, "ast_streamfile of %s failed on %s\n", tmp[i], dchan->name);
171 ast_stopstream(dchan);
177 static int unload_module(void)
179 return ast_unregister_application(app);
182 static int load_module(void)
184 /* return ast_register_application(app, park_exec); */
185 return ast_register_application(app, parkandannounce_exec, synopsis, descrip);
188 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Call Parking and Announce Application");