00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033 #include "asterisk.h"
00034
00035 ASTERISK_FILE_VERSION(__FILE__, "$Revision: 115850 $")
00036
00037 #include "asterisk/file.h"
00038 #include "asterisk/channel.h"
00039 #include "asterisk/pbx.h"
00040 #include "asterisk/module.h"
00041 #include "asterisk/lock.h"
00042 #include "asterisk/app.h"
00043
00044 static char *app = "Skel";
00045 static char *synopsis =
00046 "Skeleton application.";
00047 static char *descrip = "This application is a template to build other applications from.\n"
00048 " It shows you the basic structure to create your own Asterisk applications.\n";
00049
00050 enum {
00051 OPTION_A = (1 << 0),
00052 OPTION_B = (1 << 1),
00053 OPTION_C = (1 << 2),
00054 } option_flags;
00055
00056 enum {
00057 OPTION_ARG_B = 0,
00058 OPTION_ARG_C = 1,
00059
00060 OPTION_ARG_ARRAY_SIZE = 2,
00061 } option_args;
00062
00063 AST_APP_OPTIONS(app_opts,{
00064 AST_APP_OPTION('a', OPTION_A),
00065 AST_APP_OPTION_ARG('b', OPTION_B, OPTION_ARG_B),
00066 AST_APP_OPTION_ARG('c', OPTION_C, OPTION_ARG_C),
00067 });
00068
00069
00070 static int app_exec(struct ast_channel *chan, void *data)
00071 {
00072 int res = 0;
00073 struct ast_flags flags;
00074 char *parse, *opts[OPTION_ARG_ARRAY_SIZE];
00075 AST_DECLARE_APP_ARGS(args,
00076 AST_APP_ARG(dummy);
00077 AST_APP_ARG(options);
00078 );
00079
00080 if (ast_strlen_zero(data)) {
00081 ast_log(LOG_WARNING, "%s requires an argument (dummy[,options])\n", app);
00082 return -1;
00083 }
00084
00085
00086
00087
00088 parse = ast_strdupa(data);
00089
00090 AST_STANDARD_APP_ARGS(args, parse);
00091
00092 if (args.argc == 2)
00093 ast_app_parse_options(app_opts, &flags, opts, args.options);
00094
00095 if (!ast_strlen_zero(args.dummy))
00096 ast_log(LOG_NOTICE, "Dummy value is : %s\n", args.dummy);
00097
00098 if (ast_test_flag(&flags, OPTION_A))
00099 ast_log(LOG_NOTICE, "Option A is set\n");
00100
00101 if (ast_test_flag(&flags, OPTION_B))
00102 ast_log(LOG_NOTICE, "Option B is set with : %s\n", opts[OPTION_ARG_B] ? opts[OPTION_ARG_B] : "<unspecified>");
00103
00104 if (ast_test_flag(&flags, OPTION_C))
00105 ast_log(LOG_NOTICE, "Option C is set with : %s\n", opts[OPTION_ARG_C] ? opts[OPTION_ARG_C] : "<unspecified>");
00106
00107 return res;
00108 }
00109
00110 static int unload_module(void)
00111 {
00112 return ast_unregister_application(app);
00113 }
00114
00115 static int load_module(void)
00116 {
00117 return ast_register_application(app, app_exec, synopsis, descrip) ?
00118 AST_MODULE_LOAD_DECLINE : AST_MODULE_LOAD_SUCCESS;
00119 }
00120
00121 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Skeleton (sample) Application");