Asterisk - The Open Source Telephony Project  18.5.0
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 <[email protected]>
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 <[email protected]>
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 */
80 static const char *stasis = "Stasis";
81 
82 /*! /brief Stasis dialplan application callback */
83 static 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);
100  AST_STANDARD_APP_ARGS(args, parse);
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 
126 static int load_module(void)
127 {
129 }
130 
131 static int unload_module(void)
132 {
134 }
135 
136 AST_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",
141 );
Main Channel structure associated with a channel.
Asterisk main include file. File version handling, generic pbx functions.
#define MAX_ARGS
Maximum number of arguments for the Stasis dialplan application.
Definition: app_stasis.c:77
#define AST_STANDARD_APP_ARGS(args, parse)
Performs the &#39;standard&#39; argument separation process for an application.
Stasis Message Bus API. See Stasis Message Bus API for detailed documentation.
#define LOG_WARNING
Definition: logger.h:274
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:1324
#define ast_assert(a)
Definition: utils.h:695
const char * args
#define NULL
Definition: resample.c:96
int ast_unregister_application(const char *app)
Unregister an application.
Definition: pbx_app.c:392
#define ast_log
Definition: astobj2.c:42
static int load_module(void)
Definition: app_stasis.c:126
#define ast_strdupa(s)
duplicate a string in memory from the stack
Definition: astmm.h:300
Core PBX routines and definitions.
int ast_check_hangup(struct ast_channel *chan)
Check to see if a channel is needing hang up.
Definition: channel.c:445
Backend API for implementing components of res_stasis.
static int unload_module(void)
Definition: app_stasis.c:131
const char * app_name(struct ast_app *app)
Definition: pbx_app.c:463
static void parse(struct mgcp_request *req)
Definition: chan_mgcp.c:1872
static const char * stasis
Dialplan application name.
Definition: app_stasis.c:80
AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_GLOBAL_SYMBOLS|AST_MODFLAG_LOAD_ORDER, "HTTP Phone Provisioning",.support_level=AST_MODULE_SUPPORT_EXTENDED,.load=load_module,.unload=unload_module,.reload=reload,.load_pri=AST_MODPRI_CHANNEL_DEPEND,.requires="http",)
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...
#define ASTERISK_GPL_KEY
The text the key() function should return.
Definition: module.h:46
Asterisk module definitions.
#define AST_DECLARE_APP_ARGS(name, arglist)
Declare a structure to hold an application&#39;s arguments.
Application convenience functions, designed to give consistent look and feel to Asterisk apps...
static int app_exec(struct ast_channel *chan, const char *data)
Definition: app_stasis.c:83
#define ast_register_application_xml(app, execute)
Register an application using XML documentation.
Definition: module.h:626
#define AST_APP_ARG(name)
Define an application argument.