(closes issue #12846)
[asterisk-bristuff.git] / apps / app_skel.c
blob55830ebee86fdf0f239c971946f35c793edddf2f
1 /*
2 * Asterisk -- An open source telephony toolkit.
4 * Copyright (C) <Year>, <Your Name Here>
6 * <Your Name Here> <<Your Email Here>>
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.
19 /*! \file
21 * \brief Skeleton application
23 * \author <Your Name Here> <<Your Email Here>>
25 * This is a skeleton for development of an Asterisk application
26 * \ingroup applications
29 /*** MODULEINFO
30 <defaultenabled>no</defaultenabled>
31 ***/
33 #include "asterisk.h"
35 ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
37 #include <stdio.h>
38 #include <stdlib.h>
39 #include <unistd.h>
40 #include <string.h>
42 #include "asterisk/file.h"
43 #include "asterisk/logger.h"
44 #include "asterisk/channel.h"
45 #include "asterisk/pbx.h"
46 #include "asterisk/module.h"
47 #include "asterisk/lock.h"
48 #include "asterisk/app.h"
50 static char *app = "Skel";
51 static char *synopsis =
52 "Skeleton application.";
53 static char *descrip = "This application is a template to build other applications from.\n"
54 " It shows you the basic structure to create your own Asterisk applications.\n";
56 enum {
57 OPTION_A = (1 << 0),
58 OPTION_B = (1 << 1),
59 OPTION_C = (1 << 2),
60 } option_flags;
62 enum {
63 OPTION_ARG_B = 0,
64 OPTION_ARG_C = 1,
65 /* This *must* be the last value in this enum! */
66 OPTION_ARG_ARRAY_SIZE = 2,
67 } option_args;
69 AST_APP_OPTIONS(app_opts,{
70 AST_APP_OPTION('a', OPTION_A),
71 AST_APP_OPTION_ARG('b', OPTION_B, OPTION_ARG_B),
72 AST_APP_OPTION_ARG('c', OPTION_C, OPTION_ARG_C),
73 });
76 static int app_exec(struct ast_channel *chan, void *data)
78 int res = 0;
79 struct ast_flags flags;
80 struct ast_module_user *u;
81 char *parse, *opts[OPTION_ARG_ARRAY_SIZE];
82 AST_DECLARE_APP_ARGS(args,
83 AST_APP_ARG(dummy);
84 AST_APP_ARG(options);
87 if (ast_strlen_zero(data)) {
88 ast_log(LOG_WARNING, "%s requires an argument (dummy|[options])\n", app);
89 return -1;
92 u = ast_module_user_add(chan);
94 /* Do our thing here */
96 /* We need to make a copy of the input string if we are going to modify it! */
97 parse = ast_strdupa(data);
99 AST_STANDARD_APP_ARGS(args, parse);
101 if (args.argc == 2)
102 ast_app_parse_options(app_opts, &flags, opts, args.options);
104 if (!ast_strlen_zero(args.dummy))
105 ast_log(LOG_NOTICE, "Dummy value is : %s\n", args.dummy);
107 if (ast_test_flag(&flags, OPTION_A))
108 ast_log(LOG_NOTICE, "Option A is set\n");
110 if (ast_test_flag(&flags, OPTION_B))
111 ast_log(LOG_NOTICE, "Option B is set with : %s\n", opts[OPTION_ARG_B] ? opts[OPTION_ARG_B] : "<unspecified>");
113 if (ast_test_flag(&flags, OPTION_C))
114 ast_log(LOG_NOTICE, "Option C is set with : %s\n", opts[OPTION_ARG_C] ? opts[OPTION_ARG_C] : "<unspecified>");
116 ast_module_user_remove(u);
118 return res;
121 static int unload_module(void)
123 int res;
124 res = ast_unregister_application(app);
125 return res;
128 static int load_module(void)
130 return ast_register_application(app, app_exec, synopsis, descrip);
133 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Skeleton (sample) Application");