Asterisk - The Open Source Telephony Project GIT-master-7e7a603
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 <synopsis>Invoke an external Stasis application.</synopsis>
42 <syntax>
43 <parameter name="app_name" required="true">
44 <para>Name of the application to invoke.</para>
45 </parameter>
46 <parameter name="args">
47 <para>Optional comma-delimited arguments for the
48 application invocation.</para>
49 </parameter>
50 </syntax>
51 <description>
52 <para>Invoke a Stasis application.</para>
53 <para>This application will set the following channel variable upon
54 completion:</para>
55 <variablelist>
56 <variable name="STASISSTATUS">
57 <para>This indicates the status of the execution of the
58 Stasis application.</para>
59 <value name="SUCCESS">
60 The channel has exited Stasis without any failures in
61 Stasis.
62 </value>
63 <value name="FAILED">
64 A failure occurred when executing the Stasis
65 The app registry is not instantiated; The app
66 application. Some (not all) possible reasons for this:
67 requested is not registered; The app requested is not
68 active; Stasis couldn't send a start message.
69 </value>
70 </variable>
71 </variablelist>
72 </description>
73 </application>
74 ***/
75
76/*! \brief Maximum number of arguments for the Stasis dialplan application */
77#define MAX_ARGS 128
78
79/*! \brief Dialplan application name */
80static const char *stasis = "Stasis";
81
82/*! \brief Stasis dialplan application callback */
83static int app_exec(struct ast_channel *chan, const char *data)
84{
85 char *parse = NULL;
86 int ret = -1;
87
90 AST_APP_ARG(app_argv)[MAX_ARGS];
91 );
92
93 ast_assert(chan != NULL);
94 ast_assert(data != NULL);
95
96 pbx_builtin_setvar_helper(chan, "STASISSTATUS", "");
97
98 /* parse the arguments */
99 parse = ast_strdupa(data);
101
102 if (args.argc < 1) {
103 ast_log(LOG_WARNING, "Stasis app_name argument missing\n");
104 } else {
105 ret = stasis_app_exec(chan,
106 args.app_name,
107 args.argc - 1,
108 args.app_argv);
109 }
110
111 if (ret) {
112 /* set ret to 0 so pbx_core doesnt hangup the channel */
113 if (!ast_check_hangup(chan)) {
114 ret = 0;
115 } else {
116 ret = -1;
117 }
118 pbx_builtin_setvar_helper(chan, "STASISSTATUS", "FAILED");
119 } else {
120 pbx_builtin_setvar_helper(chan, "STASISSTATUS", "SUCCESS");
121 }
122
123 return ret;
124}
125
126static int load_module(void)
127{
129}
130
131static int unload_module(void)
132{
134}
135
136AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_DEFAULT, "Stasis dialplan application",
137 .support_level = AST_MODULE_SUPPORT_CORE,
138 .load = load_module,
139 .unload = unload_module,
140 .requires = "res_stasis",
#define MAX_ARGS
Maximum number of arguments for the Stasis dialplan application.
Definition: app_stasis.c:77
static const char * stasis
Dialplan application name.
Definition: app_stasis.c:80
static int app_exec(struct ast_channel *chan, const char *data)
Stasis dialplan application callback.
Definition: app_stasis.c:83
static int load_module(void)
Definition: app_stasis.c:126
static int unload_module(void)
Definition: app_stasis.c:131
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:315
#define AST_MODULE_INFO(keystr, flags_to_set, desc, fields...)
Definition: module.h:543
@ 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:626
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:1327
Main Channel structure associated with a channel.
const char * args
#define ast_assert(a)
Definition: utils.h:739