Asterisk - The Open Source Telephony Project GIT-master-8924258
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Macros Modules Pages
app_stasis.c
Go to the documentation of this file.
1/*
2 * Asterisk -- An open source telephony toolkit.
3 *
4 * Copyright (C) 2012 - 2013, Digium, Inc.
5 *
6 * David M. Lee, II <dlee@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 Stasis dialplan application.
22 *
23 * \author David M. Lee, II <dlee@digium.com>
24 */
25
26/*** MODULEINFO
27 <depend>res_stasis</depend>
28 <support_level>core</support_level>
29 ***/
30
31#include "asterisk.h"
32
33#include "asterisk/app.h"
34#include "asterisk/module.h"
35#include "asterisk/pbx.h"
36#include "asterisk/stasis.h"
38
39/*** DOCUMENTATION
40 <application name="Stasis" language="en_US">
41 <since>
42 <version>12.0.0</version>
43 </since>
44 <synopsis>Invoke an external Stasis application.</synopsis>
45 <syntax>
46 <parameter name="app_name" required="true">
47 <para>Name of the application to invoke.</para>
48 </parameter>
49 <parameter name="args">
50 <para>Optional comma-delimited arguments for the
51 application invocation.</para>
52 </parameter>
53 </syntax>
54 <description>
55 <para>Invoke a Stasis application.</para>
56 <para>This application will set the following channel variable upon
57 completion:</para>
58 <variablelist>
59 <variable name="STASISSTATUS">
60 <para>This indicates the status of the execution of the
61 Stasis application.</para>
62 <value name="SUCCESS">
63 The channel has exited Stasis without any failures in
64 Stasis.
65 </value>
66 <value name="FAILED">
67 A failure occurred when executing the Stasis
68 The app registry is not instantiated; The app
69 application. Some (not all) possible reasons for this:
70 requested is not registered; The app requested is not
71 active; Stasis couldn't send a start message.
72 </value>
73 </variable>
74 </variablelist>
75 </description>
76 </application>
77 ***/
78
79/*! \brief Maximum number of arguments for the Stasis dialplan application */
80#define MAX_ARGS 128
81
82/*! \brief Dialplan application name */
83static const char *stasis = "Stasis";
84
85/*! \brief Stasis dialplan application callback */
86static int app_exec(struct ast_channel *chan, const char *data)
87{
88 char *parse = NULL;
89 int ret = -1;
90
93 AST_APP_ARG(app_argv)[MAX_ARGS];
94 );
95
96 ast_assert(chan != NULL);
97 ast_assert(data != NULL);
98
99 pbx_builtin_setvar_helper(chan, "STASISSTATUS", "");
100
101 /* parse the arguments */
102 parse = ast_strdupa(data);
104
105 if (args.argc < 1) {
106 ast_log(LOG_WARNING, "Stasis app_name argument missing\n");
107 } else {
108 ret = stasis_app_exec(chan,
109 args.app_name,
110 args.argc - 1,
111 args.app_argv);
112 }
113
114 if (ret) {
115 /* set ret to 0 so pbx_core doesnt hangup the channel */
116 if (!ast_check_hangup(chan)) {
117 ret = 0;
118 } else {
119 ret = -1;
120 }
121 pbx_builtin_setvar_helper(chan, "STASISSTATUS", "FAILED");
122 } else {
123 pbx_builtin_setvar_helper(chan, "STASISSTATUS", "SUCCESS");
124 }
125
126 return ret;
127}
128
129static int load_module(void)
130{
132}
133
134static int unload_module(void)
135{
137}
138
139AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_DEFAULT, "Stasis dialplan application",
140 .support_level = AST_MODULE_SUPPORT_CORE,
141 .load = load_module,
142 .unload = unload_module,
143 .requires = "res_stasis",
#define MAX_ARGS
Maximum number of arguments for the Stasis dialplan application.
Definition: app_stasis.c:80
static const char * stasis
Dialplan application name.
Definition: app_stasis.c:83
static int app_exec(struct ast_channel *chan, const char *data)
Stasis dialplan application callback.
Definition: app_stasis.c:86
static int load_module(void)
Definition: app_stasis.c:129
static int unload_module(void)
Definition: app_stasis.c:134
Asterisk main include file. File version handling, generic pbx functions.
#define ast_strdupa(s)
duplicate a string in memory from the stack
Definition: astmm.h:298
#define ast_log
Definition: astobj2.c:42
int ast_check_hangup(struct ast_channel *chan)
Check to see if a channel is needing hang up.
Definition: channel.c:445
Application convenience functions, designed to give consistent look and feel to Asterisk apps.
#define AST_APP_ARG(name)
Define an application argument.
#define AST_DECLARE_APP_ARGS(name, arglist)
Declare a structure to hold an application's arguments.
#define AST_STANDARD_APP_ARGS(args, parse)
Performs the 'standard' argument separation process for an application.
#define LOG_WARNING
Asterisk module definitions.
@ AST_MODFLAG_DEFAULT
Definition: module.h:329
#define AST_MODULE_INFO(keystr, flags_to_set, desc, fields...)
Definition: module.h:557
@ AST_MODULE_SUPPORT_CORE
Definition: module.h:121
#define ASTERISK_GPL_KEY
The text the key() function should return.
Definition: module.h:46
int ast_unregister_application(const char *app)
Unregister an application.
Definition: pbx_app.c:392
#define ast_register_application_xml(app, execute)
Register an application using XML documentation.
Definition: module.h:640
Core PBX routines and definitions.
int pbx_builtin_setvar_helper(struct ast_channel *chan, const char *name, const char *value)
Add a variable to the channel variable stack, removing the most recently set value for the same name.
const char * app_name(struct ast_app *app)
Definition: pbx_app.c:463
#define NULL
Definition: resample.c:96
Stasis Message Bus API. See Stasis Message Bus API for detailed documentation.
Backend API for implementing components of res_stasis.
int stasis_app_exec(struct ast_channel *chan, const char *app_name, int argc, char *argv[])
Control a channel using stasis_app.
Definition: res_stasis.c:1369
Main Channel structure associated with a channel.
const char * args
#define ast_assert(a)
Definition: utils.h:739