Asterisk - The Open Source Telephony Project GIT-master-66c01d8
Functions | Variables
app_transfer.c File Reference

Transfer a caller. More...

#include "asterisk.h"
#include "asterisk/pbx.h"
#include "asterisk/module.h"
#include "asterisk/app.h"
#include "asterisk/channel.h"
Include dependency graph for app_transfer.c:

Go to the source code of this file.

Functions

static void __reg_module (void)
 
static void __unreg_module (void)
 
struct ast_moduleAST_MODULE_SELF_SYM (void)
 
static int load_module (void)
 
static int transfer_exec (struct ast_channel *chan, const char *data)
 
static int unload_module (void)
 

Variables

static struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_LOAD_ORDER , .description = "Transfers a caller to another extension" , .key = "This paragraph is copyright (c) 2006 by Digium, Inc. \In order for your module to load, it must return this \key via a function called \"key\". Any code which \includes this paragraph must be licensed under the GNU \General Public License version 2 or later (at your \option). In addition to Digium's general reservations \of rights, Digium expressly reserves the right to \allow other parties to license this paragraph under \different terms. Any use of Digium, Inc. trademarks or \logos (including \"Asterisk\" or \"Digium\") without \express written permission of Digium, Inc. is prohibited.\n" , .buildopt_sum = AST_BUILDOPT_SUM, .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_DEFAULT, .support_level = AST_MODULE_SUPPORT_CORE, }
 
static const char *const app = "Transfer"
 
static const struct ast_module_infoast_module_info = &__mod_info
 

Detailed Description

Transfer a caller.

Author
Mark Spencer marks.nosp@m.ter@.nosp@m.digiu.nosp@m.m.co.nosp@m.m

Requires transfer support from channel driver

Definition in file app_transfer.c.

Function Documentation

◆ __reg_module()

static void __reg_module ( void  )
static

Definition at line 169 of file app_transfer.c.

◆ __unreg_module()

static void __unreg_module ( void  )
static

Definition at line 169 of file app_transfer.c.

◆ AST_MODULE_SELF_SYM()

struct ast_module * AST_MODULE_SELF_SYM ( void  )

Definition at line 169 of file app_transfer.c.

◆ load_module()

static int load_module ( void  )
static

Definition at line 164 of file app_transfer.c.

165{
167}
static const char *const app
Definition: app_transfer.c:88
static int transfer_exec(struct ast_channel *chan, const char *data)
Definition: app_transfer.c:90
#define ast_register_application_xml(app, execute)
Register an application using XML documentation.
Definition: module.h:640

References app, ast_register_application_xml, and transfer_exec().

◆ transfer_exec()

static int transfer_exec ( struct ast_channel chan,
const char *  data 
)
static

Definition at line 90 of file app_transfer.c.

91{
92 int res;
93 int len;
94 char *slash;
95 char *tech = NULL;
96 char *dest = NULL;
97 char *status;
98 char *parse;
99 int protocol = 0;
100 char status_protocol[20];
102 AST_APP_ARG(dest);
103 );
104
105 if (ast_strlen_zero((char *)data)) {
106 ast_log(LOG_WARNING, "Transfer requires an argument ([Tech/]destination)\n");
107 pbx_builtin_setvar_helper(chan, "TRANSFERSTATUS", "FAILURE");
108 snprintf(status_protocol, sizeof(status_protocol), "%d", protocol);
109 pbx_builtin_setvar_helper(chan, "TRANSFERSTATUSPROTOCOL", status_protocol);
110 return 0;
111 } else
112 parse = ast_strdupa(data);
113
115
116 dest = args.dest;
117
118 if ((slash = strchr(dest, '/')) && (len = (slash - dest))) {
119 tech = dest;
120 dest = slash + 1;
121 /* Allow execution only if the Tech/destination agrees with the type of the channel */
122 if (strncasecmp(ast_channel_tech(chan)->type, tech, len)) {
123 pbx_builtin_setvar_helper(chan, "TRANSFERSTATUS", "FAILURE");
124 snprintf(status_protocol, sizeof(status_protocol), "%d", protocol);
125 pbx_builtin_setvar_helper(chan, "TRANSFERSTATUSPROTOCOL", status_protocol);
126 return 0;
127 }
128 }
129
130 /* Check if the channel supports transfer before we try it */
131 if (!ast_channel_tech(chan)->transfer) {
132 pbx_builtin_setvar_helper(chan, "TRANSFERSTATUS", "UNSUPPORTED");
133 snprintf(status_protocol, sizeof(status_protocol), "%d", protocol);
134 pbx_builtin_setvar_helper(chan, "TRANSFERSTATUSPROTOCOL", status_protocol);
135 return 0;
136 }
137
138 /* New transfer API returns a protocol code
139 SIP example, 0 = success, 3xx-6xx are sip error codes for the REFER */
140 res = ast_transfer_protocol(chan, dest, &protocol);
141
142 if (res < 0) {
143 status = "FAILURE";
144 res = 0;
145 } else {
146 status = "SUCCESS";
147 res = 0;
148 }
149
150 snprintf(status_protocol, sizeof(status_protocol), "%d", protocol);
151 ast_debug(1, "ast_transfer channel %s TRANSFERSTATUS=%s, TRANSFERSTATUSPROTOCOL=%s\n",
152 ast_channel_name(chan), status, status_protocol);
153 pbx_builtin_setvar_helper(chan, "TRANSFERSTATUS", status);
154 pbx_builtin_setvar_helper(chan, "TRANSFERSTATUSPROTOCOL", status_protocol);
155
156 return res;
157}
jack_status_t status
Definition: app_jack.c:149
#define ast_strdupa(s)
duplicate a string in memory from the stack
Definition: astmm.h:298
#define ast_log
Definition: astobj2.c:42
static const char type[]
Definition: chan_ooh323.c:109
static int transfer(void *data)
Definition: chan_pjsip.c:2133
const char * ast_channel_name(const struct ast_channel *chan)
int ast_transfer_protocol(struct ast_channel *chan, char *dest, int *protocol)
Transfer a channel (if supported) receieve protocol result.
Definition: channel.c:6515
const struct ast_channel_tech * ast_channel_tech(const struct ast_channel *chan)
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
#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 ast_debug(level,...)
Log a DEBUG message.
#define LOG_WARNING
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 NULL
Definition: resample.c:96
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition: strings.h:65
const char * args

References args, AST_APP_ARG, ast_channel_name(), ast_channel_tech(), ast_debug, AST_DECLARE_APP_ARGS, ast_log, AST_STANDARD_APP_ARGS, ast_strdupa, ast_strlen_zero(), ast_transfer_protocol(), len(), LOG_WARNING, NULL, pbx_builtin_setvar_helper(), status, transfer(), and type.

Referenced by load_module().

◆ unload_module()

static int unload_module ( void  )
static

Definition at line 159 of file app_transfer.c.

160{
162}
int ast_unregister_application(const char *app)
Unregister an application.
Definition: pbx_app.c:392

References app, and ast_unregister_application().

Variable Documentation

◆ __mod_info

struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_LOAD_ORDER , .description = "Transfers a caller to another extension" , .key = "This paragraph is copyright (c) 2006 by Digium, Inc. \In order for your module to load, it must return this \key via a function called \"key\". Any code which \includes this paragraph must be licensed under the GNU \General Public License version 2 or later (at your \option). In addition to Digium's general reservations \of rights, Digium expressly reserves the right to \allow other parties to license this paragraph under \different terms. Any use of Digium, Inc. trademarks or \logos (including \"Asterisk\" or \"Digium\") without \express written permission of Digium, Inc. is prohibited.\n" , .buildopt_sum = AST_BUILDOPT_SUM, .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_DEFAULT, .support_level = AST_MODULE_SUPPORT_CORE, }
static

Definition at line 169 of file app_transfer.c.

◆ app

const char* const app = "Transfer"
static

Definition at line 88 of file app_transfer.c.

Referenced by load_module(), and unload_module().

◆ ast_module_info

const struct ast_module_info* ast_module_info = &__mod_info
static

Definition at line 169 of file app_transfer.c.