Asterisk - The Open Source Telephony Project  18.5.0
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 = "30ef0c93b36035ec78c9cfd712d36d9b" , .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 166 of file app_transfer.c.

◆ __unreg_module()

static void __unreg_module ( void  )
static

Definition at line 166 of file app_transfer.c.

◆ AST_MODULE_SELF_SYM()

struct ast_module* AST_MODULE_SELF_SYM ( void  )

Definition at line 166 of file app_transfer.c.

◆ load_module()

static int load_module ( void  )
static

Definition at line 161 of file app_transfer.c.

References app, ast_register_application_xml, and transfer_exec().

162 {
164 }
static const char *const app
Definition: app_transfer.c:85
static int transfer_exec(struct ast_channel *chan, const char *data)
Definition: app_transfer.c:87
#define ast_register_application_xml(app, execute)
Register an application using XML documentation.
Definition: module.h:626

◆ transfer_exec()

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

Definition at line 87 of file app_transfer.c.

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, parse(), pbx_builtin_setvar_helper(), status, transfer, and type.

Referenced by load_module().

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

◆ unload_module()

static int unload_module ( void  )
static

Definition at line 156 of file app_transfer.c.

References app, and ast_unregister_application().

157 {
159 }
static const char *const app
Definition: app_transfer.c:85
int ast_unregister_application(const char *app)
Unregister an application.
Definition: pbx_app.c:392

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 = "30ef0c93b36035ec78c9cfd712d36d9b" , .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_DEFAULT, .support_level = AST_MODULE_SUPPORT_CORE, }
static

Definition at line 166 of file app_transfer.c.

◆ app

const char* const app = "Transfer"
static

Definition at line 85 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 166 of file app_transfer.c.