Wed Jan 8 2020 09:49:40

Asterisk developer's documentation


app_skel.c
Go to the documentation of this file.
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: 328209 $")
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 
79  OPTION_A = (1 << 0),
80  OPTION_B = (1 << 1),
81  OPTION_C = (1 << 2),
82 };
83 
87  /* This *must* be the last value in this enum! */
89 };
90 
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];
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) ?
152 }
153 
154 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Skeleton (sample) Application");
Main Channel structure associated with a channel.
Definition: channel.h:742
#define AST_MODULE_INFO_STANDARD(keystr, desc)
Definition: module.h:396
#define AST_APP_OPTION_ARG(option, flagno, argno)
Declares an application option that accepts an argument.
Definition: app.h:732
Asterisk locking-related definitions:
Asterisk main include file. File version handling, generic pbx functions.
#define AST_APP_OPTIONS(holder, options...)
Declares an array of options for an application.
Definition: app.h:712
#define ast_test_flag(p, flag)
Definition: utils.h:63
static struct ast_app_option app_opts[128]
Definition: app_skel.c:95
#define LOG_WARNING
Definition: logger.h:144
static void dummy(char *unused,...)
Definition: chan_unistim.c:188
int ast_app_parse_options(const struct ast_app_option *options, struct ast_flags *flags, char **args, char *optstr)
Parses a string containing application options and sets flags/arguments.
Definition: app.c:2101
#define AST_DECLARE_APP_ARGS(name, arglist)
Declare a structure to hold an application&#39;s arguments.
Definition: app.h:572
int ast_unregister_application(const char *app)
Unregister an application.
Definition: pbx.c:7705
General Asterisk PBX channel definitions.
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition: strings.h:63
Core PBX routines and definitions.
static int app_exec(struct ast_channel *chan, const char *data)
Definition: app_skel.c:98
#define ast_strdupa(s)
duplicate a string in memory from the stack
Definition: utils.h:663
static struct @350 args
void ast_log(int level, const char *file, int line, const char *function, const char *fmt,...)
Used for sending a log message This is the standard logger function. Probably the only way you will i...
Definition: logger.c:1207
#define LOG_NOTICE
Definition: logger.h:133
static void parse(struct mgcp_request *req)
Definition: chan_mgcp.c:1858
static char * app
Definition: app_skel.c:76
Structure used to handle boolean flags.
Definition: utils.h:200
static int unload_module(void)
Definition: app_skel.c:143
option_flags
Definition: app_skel.c:78
Application convenience functions, designed to give consistent look and feel to Asterisk apps...
static int load_module(void)
Definition: app_skel.c:148
#define AST_APP_ARG(name)
Define an application argument.
Definition: app.h:555
option_args
Definition: app_skel.c:84
#define AST_STANDARD_APP_ARGS(args, parse)
Performs the &#39;standard&#39; argument separation process for an application.
Definition: app.h:604
#define ASTERISK_GPL_KEY
The text the key() function should return.
Definition: module.h:38
Asterisk module definitions.
#define ast_register_application_xml(app, execute)
Register an application using XML documentation.
Definition: module.h:437
#define ASTERISK_FILE_VERSION(file, version)
Register/unregister a source code file with the core.
Definition: asterisk.h:180
#define AST_APP_OPTION(option, flagno)
Declares an application option that does not accept an argument.
Definition: app.h:721