Wed Jan 8 2020 09:49:39

Asterisk developer's documentation


app_channelredirect.c
Go to the documentation of this file.
1 /*
2  * Asterisk -- An open source telephony toolkit.
3  *
4  * Copyright (C) 2006, Sergey Basmanov
5  *
6  * See http://www.asterisk.org for more information about
7  * the Asterisk project. Please do not directly contact
8  * any of the maintainers of this project for assistance;
9  * the project provides a web site, mailing lists and IRC
10  * channels for your use.
11  *
12  * This program is free software, distributed under the terms of
13  * the GNU General Public License Version 2. See the LICENSE file
14  * at the top of the source tree.
15  */
16 
17 /*! \file
18  *
19  * \brief ChannelRedirect application
20  *
21  * \author Sergey Basmanov <sergey_basmanov@mail.ru>
22  *
23  * \ingroup applications
24  */
25 
26 /*** MODULEINFO
27  <support_level>core</support_level>
28  ***/
29 
30 #include "asterisk.h"
31 
32 ASTERISK_FILE_VERSION(__FILE__, "$Revision: 328209 $")
33 
34 #include "asterisk/file.h"
35 #include "asterisk/channel.h"
36 #include "asterisk/pbx.h"
37 #include "asterisk/module.h"
38 #include "asterisk/lock.h"
39 #include "asterisk/app.h"
40 #include "asterisk/features.h"
41 
42 /*** DOCUMENTATION
43  <application name="ChannelRedirect" language="en_US">
44  <synopsis>
45  Redirects given channel to a dialplan target
46  </synopsis>
47  <syntax>
48  <parameter name="channel" required="true" />
49  <parameter name="context" required="false" />
50  <parameter name="extension" required="false" />
51  <parameter name="priority" required="true" />
52  </syntax>
53  <description>
54  <para>Sends the specified channel to the specified extension priority</para>
55 
56  <para>This application sets the following channel variables upon completion</para>
57  <variablelist>
58  <variable name="CHANNELREDIRECT_STATUS">
59  <value name="NOCHANNEL" />
60  <value name="SUCCESS" />
61  <para>Are set to the result of the redirection</para>
62  </variable>
63  </variablelist>
64  </description>
65  </application>
66  ***/
67 static const char app[] = "ChannelRedirect";
68 
69 static int asyncgoto_exec(struct ast_channel *chan, const char *data)
70 {
71  int res = -1;
72  char *info;
73  struct ast_channel *chan2 = NULL;
74 
76  AST_APP_ARG(channel);
77  AST_APP_ARG(label);
78  );
79 
80  if (ast_strlen_zero(data)) {
81  ast_log(LOG_WARNING, "%s requires an argument (channel,[[context,]exten,]priority)\n", app);
82  return -1;
83  }
84 
85  info = ast_strdupa(data);
87 
88  if (ast_strlen_zero(args.channel) || ast_strlen_zero(args.label)) {
89  ast_log(LOG_WARNING, "%s requires an argument (channel,[[context,]exten,]priority)\n", app);
90  return -1;
91  }
92 
93  if (!(chan2 = ast_channel_get_by_name(args.channel))) {
94  ast_log(LOG_WARNING, "No such channel: %s\n", args.channel);
95  pbx_builtin_setvar_helper(chan, "CHANNELREDIRECT_STATUS", "NOCHANNEL");
96  return 0;
97  }
98 
99  if (chan2->pbx) {
100  ast_set_flag(chan2, AST_FLAG_BRIDGE_HANGUP_DONT); /* don't let the after-bridge code run the h-exten */
101  }
102 
103  res = ast_async_parseable_goto(chan2, args.label);
104 
105  chan2 = ast_channel_unref(chan2);
106 
107  pbx_builtin_setvar_helper(chan, "CHANNELREDIRECT_STATUS", "SUCCESS");
108 
109  return res;
110 }
111 
112 static int unload_module(void)
113 {
114  return ast_unregister_application(app);
115 }
116 
117 static int load_module(void)
118 {
121 }
122 
123 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Redirects a given channel to a dialplan target");
Main Channel structure associated with a channel.
Definition: channel.h:742
#define AST_MODULE_INFO_STANDARD(keystr, desc)
Definition: module.h:396
Asterisk locking-related definitions:
Asterisk main include file. File version handling, generic pbx functions.
static const char app[]
#define ast_channel_unref(c)
Decrease channel reference count.
Definition: channel.h:2502
static int load_module(void)
#define ast_set_flag(p, flag)
Definition: utils.h:70
#define LOG_WARNING
Definition: logger.h:144
#define AST_DECLARE_APP_ARGS(name, arglist)
Declare a structure to hold an application&#39;s arguments.
Definition: app.h:572
const char * data
Definition: channel.h:755
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
static int asyncgoto_exec(struct ast_channel *chan, const char *data)
static int unload_module(void)
Core PBX routines and definitions.
#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
int ast_async_parseable_goto(struct ast_channel *chan, const char *goto_string)
Definition: pbx.c:11331
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...
Definition: pbx.c:10546
Application convenience functions, designed to give consistent look and feel to Asterisk apps...
#define AST_APP_ARG(name)
Define an application argument.
Definition: app.h:555
#define AST_STANDARD_APP_ARGS(args, parse)
Performs the &#39;standard&#39; argument separation process for an application.
Definition: app.h:604
Call Parking and Pickup API Includes code and algorithms from the Zapata library. ...
#define ASTERISK_GPL_KEY
The text the key() function should return.
Definition: module.h:38
struct ast_channel * ast_channel_get_by_name(const char *name)
Find a channel by name.
Definition: channel.c:1803
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
struct ast_pbx * pbx
Definition: channel.h:761