Merge "AST-2018-005: Fix tdata leaks when calling pjsip_endpt_send_response(2)"
[asterisk/asterisk.git] / apps / app_ivrdemo.c
1 /*
2  * Asterisk -- An open source telephony toolkit.
3  *
4  * Copyright (C) 1999 - 2005, Digium, Inc.
5  *
6  * Mark Spencer <markster@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 /*! \file
20  *
21  * \brief IVR Demo application
22  *
23  * \author Mark Spencer <markster@digium.com>
24  *
25  * \ingroup applications
26  */
27
28 /*** MODULEINFO
29         <defaultenabled>no</defaultenabled>
30         <support_level>extended</support_level>
31  ***/
32
33 #include "asterisk.h"
34
35 #include "asterisk/file.h"
36 #include "asterisk/channel.h"
37 #include "asterisk/pbx.h"
38 #include "asterisk/module.h"
39 #include "asterisk/lock.h"
40 #include "asterisk/app.h"
41
42 /*** DOCUMENTATION
43         <application name="IVRDemo" language="en_US">
44                 <synopsis>
45                         IVR Demo Application.
46                 </synopsis>
47                 <syntax>
48                         <parameter name="filename" required="true" />
49                 </syntax>
50                 <description>
51                         <para>This is a skeleton application that shows you the basic structure to create your
52                         own asterisk applications and demonstrates the IVR demo.</para>
53                 </description>
54         </application>
55  ***/
56
57 static char *app = "IVRDemo";
58
59 static int ivr_demo_func(struct ast_channel *chan, void *data)
60 {
61         ast_verbose("IVR Demo, data is %s!\n", (char *) data);
62         return 0;
63 }
64
65 AST_IVR_DECLARE_MENU(ivr_submenu, "IVR Demo Sub Menu", 0,
66 {
67         { "s", AST_ACTION_BACKGROUND, "demo-abouttotry" },
68         { "s", AST_ACTION_WAITOPTION },
69         { "1", AST_ACTION_PLAYBACK, "digits/1" },
70         { "1", AST_ACTION_PLAYBACK, "digits/1" },
71         { "1", AST_ACTION_RESTART },
72         { "2", AST_ACTION_PLAYLIST, "digits/2;digits/3" },
73         { "3", AST_ACTION_CALLBACK, ivr_demo_func },
74         { "4", AST_ACTION_TRANSFER, "demo|s|1" },
75         { "*", AST_ACTION_REPEAT },
76         { "#", AST_ACTION_UPONE  },
77         { NULL }
78 });
79
80 AST_IVR_DECLARE_MENU(ivr_demo, "IVR Demo Main Menu", 0,
81 {
82         { "s", AST_ACTION_BACKGROUND, "demo-congrats" },
83         { "g", AST_ACTION_BACKGROUND, "demo-instruct" },
84         { "g", AST_ACTION_WAITOPTION },
85         { "1", AST_ACTION_PLAYBACK, "digits/1" },
86         { "1", AST_ACTION_RESTART },
87         { "2", AST_ACTION_MENU, &ivr_submenu },
88         { "2", AST_ACTION_RESTART },
89         { "i", AST_ACTION_PLAYBACK, "invalid" },
90         { "i", AST_ACTION_REPEAT, (void *)(unsigned long)2 },
91         { "#", AST_ACTION_EXIT },
92         { NULL },
93 });
94
95 static int skel_exec(struct ast_channel *chan, const char *data)
96 {
97         int res=0;
98         char *tmp;
99
100         if (ast_strlen_zero(data)) {
101                 ast_log(LOG_WARNING, "skel requires an argument (filename)\n");
102                 return -1;
103         }
104
105         tmp = ast_strdupa(data);
106
107         /* Do our thing here */
108
109         if (ast_channel_state(chan) != AST_STATE_UP)
110                 res = ast_answer(chan);
111         if (!res)
112                 res = ast_ivr_menu_run(chan, &ivr_demo, tmp);
113
114         return res;
115 }
116
117 static int unload_module(void)
118 {
119         return ast_unregister_application(app);
120 }
121
122 static int load_module(void)
123 {
124         return ast_register_application_xml(app, skel_exec);
125 }
126
127 AST_MODULE_INFO_STANDARD_EXTENDED(ASTERISK_GPL_KEY, "IVR Demo Application");