Merged revisions 333203 via svnmerge from
[asterisk/asterisk.git] / apps / app_skel.c
1 /*
2  * Asterisk -- An open source telephony toolkit.
3  *
4  * Copyright (C) <Year>, <Your Name Here>
5  *
6  * <Your Name Here> <<Your Email Here>>
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  * Please follow coding guidelines 
19  * http://svn.digium.com/view/asterisk/trunk/doc/CODING-GUIDELINES
20  */
21
22 /*! \file
23  *
24  * \brief Skeleton application
25  *
26  * \author\verbatim <Your Name Here> <<Your Email Here>> \endverbatim
27  * 
28  * This is a skeleton for development of an Asterisk application 
29  * \ingroup applications
30  */
31
32 /*** MODULEINFO
33         <defaultenabled>no</defaultenabled>
34         <support_level>core</support_level>
35  ***/
36
37 #include "asterisk.h"
38
39 ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
40
41 #include "asterisk/file.h"
42 #include "asterisk/channel.h"
43 #include "asterisk/pbx.h"
44 #include "asterisk/module.h"
45 #include "asterisk/lock.h"
46 #include "asterisk/app.h"
47
48 /*** DOCUMENTATION
49         <application name="Skel" language="en_US">
50                 <synopsis>
51                         Simple one line explaination.
52                 </synopsis>
53                 <syntax>
54                         <parameter name="dummy" required="true"/>
55                         <parameter name="options">
56                                 <optionlist>
57                                         <option name="a">
58                                                 <para>Option A.</para>
59                                         </option>
60                                         <option name="b">
61                                                 <para>Option B.</para>
62                                         </option>
63                                         <option name="c">
64                                                 <para>Option C.</para>
65                                         </option>
66                                 </optionlist>
67                         </parameter>
68                 </syntax>
69                 <description>
70                 <para>This application is a template to build other applications from. 
71                 It shows you the basic structure to create your own Asterisk applications.</para>
72                 </description>
73         </application>
74  ***/
75
76 static char *app = "Skel";
77
78 enum option_flags {
79         OPTION_A = (1 << 0),
80         OPTION_B = (1 << 1),
81         OPTION_C = (1 << 2),
82 };
83
84 enum option_args {
85         OPTION_ARG_B = 0,
86         OPTION_ARG_C = 1,
87         /* This *must* be the last value in this enum! */
88         OPTION_ARG_ARRAY_SIZE = 2,
89 };
90
91 AST_APP_OPTIONS(app_opts,{
92         AST_APP_OPTION('a', OPTION_A),
93         AST_APP_OPTION_ARG('b', OPTION_B, OPTION_ARG_B),
94         AST_APP_OPTION_ARG('c', OPTION_C, OPTION_ARG_C),
95 });
96
97
98 static int app_exec(struct ast_channel *chan, const char *data)
99 {
100         int res = 0;
101         struct ast_flags flags;
102         char *parse, *opts[OPTION_ARG_ARRAY_SIZE];
103         AST_DECLARE_APP_ARGS(args,
104                 AST_APP_ARG(dummy);
105                 AST_APP_ARG(options);
106         );
107
108         if (ast_strlen_zero(data)) {
109                 ast_log(LOG_WARNING, "%s requires an argument (dummy[,options])\n", app);
110                 return -1;
111         }
112
113         /* Do our thing here */
114
115         /* We need to make a copy of the input string if we are going to modify it! */
116         parse = ast_strdupa(data);
117
118         AST_STANDARD_APP_ARGS(args, parse);
119
120         if (args.argc == 2) {
121                 ast_app_parse_options(app_opts, &flags, opts, args.options);
122         }
123
124         if (!ast_strlen_zero(args.dummy)) {
125                 ast_log(LOG_NOTICE, "Dummy value is : %s\n", args.dummy);
126         }
127
128         if (ast_test_flag(&flags, OPTION_A)) {
129                 ast_log(LOG_NOTICE, "Option A is set\n");
130         }
131
132         if (ast_test_flag(&flags, OPTION_B)) {
133                 ast_log(LOG_NOTICE, "Option B is set with : %s\n", opts[OPTION_ARG_B] ? opts[OPTION_ARG_B] : "<unspecified>");
134         }
135
136         if (ast_test_flag(&flags, OPTION_C)) {
137                 ast_log(LOG_NOTICE, "Option C is set with : %s\n", opts[OPTION_ARG_C] ? opts[OPTION_ARG_C] : "<unspecified>");
138         }
139
140         return res;
141 }
142
143 static int unload_module(void)
144 {
145         return ast_unregister_application(app);
146 }
147
148 static int load_module(void)
149 {
150         return ast_register_application_xml(app, app_exec) ? 
151                 AST_MODULE_LOAD_DECLINE : AST_MODULE_LOAD_SUCCESS;
152 }
153
154 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Skeleton (sample) Application");