Merge "AST-2018-005: Fix tdata leaks when calling pjsip_endpt_send_response(2)"
[asterisk/asterisk.git] / apps / app_playtones.c
1 /*
2  * Asterisk -- An open source telephony toolkit.
3  *
4  * Copyright (C) 2009, Digium, Inc.
5  *
6  * Russell Bryant <russell@digium.com>
7  *
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.
13  *
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.
17  */
18
19 /*!
20  * \file
21  * \brief Playtones application
22  *
23  * \author Russell Bryant <russell@digium.com>
24  *
25  * \ingroup applications
26  */
27
28 /*** MODULEINFO
29         <support_level>core</support_level>
30  ***/
31
32 #include "asterisk.h"
33
34 #include "asterisk/module.h"
35 #include "asterisk/pbx.h"
36 #include "asterisk/channel.h"
37 #include "asterisk/indications.h"
38
39 static const char playtones_app[] = "PlayTones";
40 static const char stopplaytones_app[] = "StopPlayTones";
41
42 /*** DOCUMENTATION
43         <application name="PlayTones" language="en_US">
44                 <synopsis>
45                         Play a tone list.
46                 </synopsis>
47                 <syntax>
48                         <parameter name="arg" required="true">
49                                 <para>Arg is either the tone name defined in the <filename>indications.conf</filename>
50                                 configuration file, or a directly specified list of frequencies and durations.</para>
51                         </parameter>
52                 </syntax>
53                 <description>
54                         <para>Plays a tone list. Execution will continue with the next step in the dialplan
55                         immediately while the tones continue to play.</para>
56                         <para>See the sample <filename>indications.conf</filename> for a description of the
57                         specification of a tonelist.</para>
58                 </description>
59                 <see-also>
60                         <ref type="application">StopPlayTones</ref>
61                 </see-also>
62         </application>
63         <application name="StopPlayTones" language="en_US">
64                 <synopsis>
65                         Stop playing a tone list.
66                 </synopsis>
67                 <syntax />
68                 <description>
69                         <para>Stop playing a tone list, initiated by PlayTones().</para>
70                 </description>
71                 <see-also>
72                         <ref type="application">PlayTones</ref>
73                 </see-also>
74         </application>
75  ***/
76
77 static int handle_playtones(struct ast_channel *chan, const char *data)
78 {
79         struct ast_tone_zone_sound *ts;
80         int res;
81         const char *str = data;
82
83         if (ast_strlen_zero(str)) {
84                 ast_log(LOG_NOTICE,"Nothing to play\n");
85                 return -1;
86         }
87
88         ts = ast_get_indication_tone(ast_channel_zone(chan), str);
89
90         if (ts) {
91                 res = ast_playtones_start(chan, 0, ts->data, 0);
92                 ts = ast_tone_zone_sound_unref(ts);
93         } else {
94                 res = ast_playtones_start(chan, 0, str, 0);
95         }
96
97         if (res) {
98                 ast_log(LOG_NOTICE, "Unable to start playtones\n");
99         }
100
101         return res;
102 }
103
104 static int handle_stopplaytones(struct ast_channel *chan, const char *data)
105 {
106         ast_playtones_stop(chan);
107
108         return 0;
109 }
110
111 static int unload_module(void)
112 {
113         int res;
114
115         res = ast_unregister_application(playtones_app);
116         res |= ast_unregister_application(stopplaytones_app);
117
118         return res;
119 }
120
121 static int load_module(void)
122 {
123         int res;
124
125         res = ast_register_application_xml(playtones_app, handle_playtones);
126         res |= ast_register_application_xml(stopplaytones_app, handle_stopplaytones);
127
128         return res ? AST_MODULE_LOAD_DECLINE : AST_MODULE_LOAD_SUCCESS;
129 }
130
131 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Playtones Application");