Asterisk - The Open Source Telephony Project  GIT-master-9ed6387
Enumerations | Functions | Variables
app_originate.c File Reference

Originate application. More...

#include "asterisk.h"
#include "asterisk/file.h"
#include "asterisk/channel.h"
#include "asterisk/pbx.h"
#include "asterisk/module.h"
#include "asterisk/app.h"
#include "asterisk/format_cache.h"

Go to the source code of this file.

Enumerations

enum  { OPT_PREDIAL_CALLEE = (1 << 0), OPT_PREDIAL_CALLER = (1 << 1), OPT_ASYNC = (1 << 2) }
 
enum  { OPT_ARG_PREDIAL_CALLEE, OPT_ARG_PREDIAL_CALLER, OPT_ARG_ARRAY_SIZE }
 

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 originate_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 = "Originate call" , .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 app_originate [] = "Originate"
 
static const struct ast_module_infoast_module_info = &__mod_info
 
static const struct ast_app_option originate_exec_options [128] = { [ 'a' ] = { .flag = OPT_ASYNC }, [ 'b' ] = { .flag = OPT_PREDIAL_CALLEE , .arg_index = OPT_ARG_PREDIAL_CALLEE + 1 }, [ 'B' ] = { .flag = OPT_PREDIAL_CALLER , .arg_index = OPT_ARG_PREDIAL_CALLER + 1 }, }
 

Detailed Description

Originate application.

Author
Roberto Casas rober.nosp@m.to.c.nosp@m.asas@.nosp@m.diap.nosp@m.le.co.nosp@m.m
Russell Bryant russe.nosp@m.ll@d.nosp@m.igium.nosp@m..com
Todo:
Make a way to be able to set variables (and functions) on the outbound channel, similar to the Variable headers for the AMI Originate, and the Set options for call files.

Definition in file app_originate.c.

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
OPT_PREDIAL_CALLEE 
OPT_PREDIAL_CALLER 
OPT_ASYNC 

Definition at line 127 of file app_originate.c.

127  {
128  OPT_PREDIAL_CALLEE = (1 << 0),
129  OPT_PREDIAL_CALLER = (1 << 1),
130  OPT_ASYNC = (1 << 2),
131 };

◆ anonymous enum

anonymous enum
Enumerator
OPT_ARG_PREDIAL_CALLEE 
OPT_ARG_PREDIAL_CALLER 
OPT_ARG_ARRAY_SIZE 

Definition at line 133 of file app_originate.c.

133  {
136  /* note: this entry _MUST_ be the last one in the enum */
138 };

Function Documentation

◆ __reg_module()

static void __reg_module ( void  )
static

Definition at line 334 of file app_originate.c.

◆ __unreg_module()

static void __unreg_module ( void  )
static

Definition at line 334 of file app_originate.c.

◆ AST_MODULE_SELF_SYM()

struct ast_module* AST_MODULE_SELF_SYM ( void  )

Definition at line 334 of file app_originate.c.

◆ load_module()

static int load_module ( void  )
static

Definition at line 325 of file app_originate.c.

References app_originate, AST_MODULE_LOAD_DECLINE, AST_MODULE_LOAD_SUCCESS, ast_register_application_xml, and originate_exec().

326 {
327  int res;
328 
330 
332 }
static int originate_exec(struct ast_channel *chan, const char *data)
static const char app_originate[]
Definition: app_originate.c:48
Module has failed to load, may be in an inconsistent state.
Definition: module.h:78
#define ast_register_application_xml(app, execute)
Register an application using XML documentation.
Definition: module.h:626

◆ originate_exec()

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

Definition at line 147 of file app_originate.c.

References ao2_cleanup, args, AST_APP_ARG, ast_app_exec_sub(), ast_app_parse_options64(), ast_autoservice_start(), ast_autoservice_stop(), AST_CONTROL_ANSWER, AST_CONTROL_BUSY, AST_CONTROL_CONGESTION, AST_CONTROL_HANGUP, AST_CONTROL_RINGING, ast_debug, AST_DECLARE_APP_ARGS, ast_format_cap_alloc, ast_format_cap_append, AST_FORMAT_CAP_FLAG_DEFAULT, ast_format_slin, ast_format_slin12, ast_format_slin16, ast_format_slin192, ast_format_slin24, ast_format_slin32, ast_format_slin44, ast_format_slin48, ast_format_slin96, ast_log, AST_OUTGOING_NO_WAIT, AST_OUTGOING_WAIT, ast_pbx_outgoing_app_predial(), ast_pbx_outgoing_exten_predial(), ast_replace_subargument_delimiter(), AST_STANDARD_APP_ARGS, ast_strdupa, ast_strlen_zero, ast_test_flag64, exten, LOG_ERROR, LOG_NOTICE, LOG_WARNING, NULL, OPT_ARG_ARRAY_SIZE, OPT_ARG_PREDIAL_CALLEE, OPT_ARG_PREDIAL_CALLER, OPT_ASYNC, OPT_PREDIAL_CALLEE, OPT_PREDIAL_CALLER, options, originate_exec_options, parse(), pbx_builtin_setvar_helper(), priority, S_OR, strsep(), timeout, and type.

Referenced by load_module().

148 {
150  AST_APP_ARG(tech_data);
151  AST_APP_ARG(type);
152  AST_APP_ARG(arg1);
153  AST_APP_ARG(arg2);
154  AST_APP_ARG(arg3);
157  );
158  struct ast_flags64 opts = { 0, };
159  char *opt_args[OPT_ARG_ARRAY_SIZE];
160  char *predial_callee = NULL;
161  char *parse;
162  char *chantech, *chandata;
163  int res = -1;
164  int continue_in_dialplan = 0;
165  int outgoing_status = 0;
166  unsigned int timeout = 30;
167  static const char default_exten[] = "s";
169 
170  ast_autoservice_start(chan);
171  if (!cap_slin) {
172  goto return_cleanup;
173  }
174 
184 
185  if (ast_strlen_zero(data)) {
186  ast_log(LOG_ERROR, "Originate() requires arguments\n");
187  goto return_cleanup;
188  }
189 
190  parse = ast_strdupa(data);
191 
192  AST_STANDARD_APP_ARGS(args, parse);
193 
194  if (args.argc < 3) {
195  ast_log(LOG_ERROR, "Incorrect number of arguments\n");
196  goto return_cleanup;
197  }
198 
199  if (!ast_strlen_zero(args.timeout)) {
200  if(sscanf(args.timeout, "%u", &timeout) != 1) {
201  ast_log(LOG_NOTICE, "Invalid timeout: '%s'. Setting timeout to 30 seconds\n", args.timeout);
202  timeout = 30;
203  }
204  }
205 
206  chandata = ast_strdupa(args.tech_data);
207  chantech = strsep(&chandata, "/");
208 
209  if (ast_strlen_zero(chandata) || ast_strlen_zero(chantech)) {
210  ast_log(LOG_ERROR, "Channel Tech/Data invalid: '%s'\n", args.tech_data);
211  goto return_cleanup;
212  }
213 
214  if (!ast_strlen_zero(args.options) &&
215  ast_app_parse_options64(originate_exec_options, &opts, opt_args, args.options)) {
216  ast_log(LOG_ERROR, "Invalid options: '%s'\n", args.options);
217  goto return_cleanup;
218  }
219 
220  /* PREDIAL: Run gosub on the caller's channel */
222  && !ast_strlen_zero(opt_args[OPT_ARG_PREDIAL_CALLER])) {
223  ast_replace_subargument_delimiter(opt_args[OPT_ARG_PREDIAL_CALLER]);
224  ast_app_exec_sub(NULL, chan, opt_args[OPT_ARG_PREDIAL_CALLER], 0);
225  }
226 
228  && !ast_strlen_zero(opt_args[OPT_ARG_PREDIAL_CALLEE])) {
229  ast_replace_subargument_delimiter(opt_args[OPT_ARG_PREDIAL_CALLEE]);
230  predial_callee = opt_args[OPT_ARG_PREDIAL_CALLEE];
231  }
232 
233  if (strcasecmp(args.type, "exten") && strcasecmp(args.type, "app")) {
234  ast_log(LOG_ERROR, "Incorrect type, it should be 'exten' or 'app': %s\n",
235  args.type);
236  goto return_cleanup;
237  }
238 
239  if (!strcasecmp(args.type, "exten")) {
240  int priority = 1; /* Initialized in case priority not specified */
241  const char *exten = args.arg2;
242 
243  if (args.argc == 5) {
244  /* Context/Exten/Priority all specified */
245  if (sscanf(args.arg3, "%30d", &priority) != 1) {
246  ast_log(LOG_ERROR, "Invalid priority: '%s'\n", args.arg3);
247  goto return_cleanup;
248  }
249  } else if (args.argc == 3) {
250  /* Exten not specified */
251  exten = default_exten;
252  }
253 
254  ast_debug(1, "Originating call to '%s/%s' and connecting them to extension %s,%s,%d\n",
255  chantech, chandata, args.arg1, exten, priority);
256 
257  res = ast_pbx_outgoing_exten_predial(chantech, cap_slin, chandata,
258  timeout * 1000, args.arg1, exten, priority, &outgoing_status,
260  NULL, NULL, NULL, NULL, NULL, 0, NULL,
261  predial_callee);
262  } else {
263  ast_debug(1, "Originating call to '%s/%s' and connecting them to %s(%s)\n",
264  chantech, chandata, args.arg1, S_OR(args.arg2, ""));
265 
266  res = ast_pbx_outgoing_app_predial(chantech, cap_slin, chandata,
267  timeout * 1000, args.arg1, args.arg2, &outgoing_status,
269  NULL, NULL, NULL, NULL, NULL, NULL,
270  predial_callee);
271  }
272 
273  /*
274  * Getting here means that we have passed the various validation checks and
275  * have at least attempted the dial. If we have a reason (outgoing_status),
276  * we clear our error indicator so that we ultimately report the right thing
277  * to the caller.
278  */
279  if (res && outgoing_status) {
280  res = 0;
281  }
282 
283  /* We need to exit cleanly if we've gotten this far */
284  continue_in_dialplan = 1;
285 
286 return_cleanup:
287  if (res) {
288  pbx_builtin_setvar_helper(chan, "ORIGINATE_STATUS", "FAILED");
289  } else {
290  switch (outgoing_status) {
291  case 0:
292  case AST_CONTROL_ANSWER:
293  pbx_builtin_setvar_helper(chan, "ORIGINATE_STATUS", "SUCCESS");
294  break;
295  case AST_CONTROL_BUSY:
296  pbx_builtin_setvar_helper(chan, "ORIGINATE_STATUS", "BUSY");
297  break;
299  pbx_builtin_setvar_helper(chan, "ORIGINATE_STATUS", "CONGESTION");
300  break;
301  case AST_CONTROL_HANGUP:
302  pbx_builtin_setvar_helper(chan, "ORIGINATE_STATUS", "HANGUP");
303  break;
304  case AST_CONTROL_RINGING:
305  pbx_builtin_setvar_helper(chan, "ORIGINATE_STATUS", "RINGING");
306  break;
307  default:
308  ast_log(LOG_WARNING, "Unknown originate status result of '%d'\n",
309  outgoing_status);
310  pbx_builtin_setvar_helper(chan, "ORIGINATE_STATUS", "UNKNOWN");
311  break;
312  }
313  }
314  ao2_cleanup(cap_slin);
315  ast_autoservice_stop(chan);
316 
317  return continue_in_dialplan ? 0 : -1;
318 }
static const char type[]
Definition: chan_ooh323.c:109
static char exten[AST_MAX_EXTENSION]
Definition: chan_alsa.c:118
struct ast_format * ast_format_slin192
Built-in cached signed linear 192kHz format.
Definition: format_cache.c:81
int ast_autoservice_start(struct ast_channel *chan)
Automatically service a channel for us...
Definition: autoservice.c:200
struct ast_format * ast_format_slin32
Built-in cached signed linear 32kHz format.
Definition: format_cache.c:61
struct ast_format * ast_format_slin96
Built-in cached signed linear 96kHz format.
Definition: format_cache.c:76
#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
static int timeout
Definition: cdr_mysql.c:86
int ast_pbx_outgoing_exten_predial(const char *type, struct ast_format_cap *cap, const char *addr, int timeout, const char *context, const char *exten, int priority, int *reason, int synchronous, const char *cid_num, const char *cid_name, struct ast_variable *vars, const char *account, struct ast_channel **locked_channel, int early_media, const struct ast_assigned_ids *assignedids, const char *predial_callee)
Definition: pbx.c:7942
struct ast_format * ast_format_slin24
Built-in cached signed linear 24kHz format.
Definition: format_cache.c:56
const char * args
#define NULL
Definition: resample.c:96
Structure used to handle a large number of boolean flags == used only in app_dial?
Definition: utils.h:204
static int priority
struct ast_format * ast_format_slin12
Built-in cached signed linear 12kHz format.
Definition: format_cache.c:46
#define ast_debug(level,...)
Log a DEBUG message.
Definition: logger.h:444
void ast_replace_subargument_delimiter(char *s)
Replace &#39;^&#39; in a string with &#39;,&#39;.
Definition: main/utils.c:1966
#define ast_log
Definition: astobj2.c:42
#define ast_strdupa(s)
duplicate a string in memory from the stack
Definition: astmm.h:300
#define ast_format_cap_append(cap, format, framing)
Definition: format_cap.h:103
#define ast_format_cap_alloc(flags)
Definition: format_cap.h:52
int ast_app_parse_options64(const struct ast_app_option *options, struct ast_flags64 *flags, char **args, char *optstr)
Parses a string containing application options and sets flags/arguments.
Definition: main/app.c:2834
int ast_autoservice_stop(struct ast_channel *chan)
Stop servicing a channel for us...
Definition: autoservice.c:266
#define LOG_ERROR
Definition: logger.h:285
Format capabilities structure, holds formats + preference order + etc.
Definition: format_cap.c:54
static const struct ast_app_option originate_exec_options[128]
#define LOG_NOTICE
Definition: logger.h:263
#define ast_strlen_zero(a)
Definition: muted.c:73
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...
char * strsep(char **str, const char *delims)
#define ao2_cleanup(obj)
Definition: astobj2.h:1958
#define S_OR(a, b)
returns the equivalent of logic or for strings: first one if not empty, otherwise second one...
Definition: strings.h:79
int ast_app_exec_sub(struct ast_channel *autoservice_chan, struct ast_channel *sub_chan, const char *sub_args, int ignore_hangup)
Run a subroutine on a channel, placing an optional second channel into autoservice.
Definition: main/app.c:370
int ast_pbx_outgoing_app_predial(const char *type, struct ast_format_cap *cap, const char *addr, int timeout, const char *app, const char *appdata, int *reason, int synchronous, const char *cid_num, const char *cid_name, struct ast_variable *vars, const char *account, struct ast_channel **locked_channel, const struct ast_assigned_ids *assignedids, const char *predial_callee)
Definition: pbx.c:8006
struct ast_format * ast_format_slin44
Built-in cached signed linear 44kHz format.
Definition: format_cache.c:66
struct ast_format * ast_format_slin16
Built-in cached signed linear 16kHz format.
Definition: format_cache.c:51
static struct test_options options
struct ast_format * ast_format_slin
Built-in cached signed linear 8kHz format.
Definition: format_cache.c:41
#define AST_DECLARE_APP_ARGS(name, arglist)
Declare a structure to hold an application&#39;s arguments.
struct ast_format * ast_format_slin48
Built-in cached signed linear 48kHz format.
Definition: format_cache.c:71
#define AST_APP_ARG(name)
Define an application argument.
#define ast_test_flag64(p, flag)
Definition: utils.h:120

◆ unload_module()

static int unload_module ( void  )
static

Definition at line 320 of file app_originate.c.

References app_originate, and ast_unregister_application().

321 {
323 }
int ast_unregister_application(const char *app)
Unregister an application.
Definition: pbx_app.c:392
static const char app_originate[]
Definition: app_originate.c:48

Variable Documentation

◆ __mod_info

struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_LOAD_ORDER , .description = "Originate call" , .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 334 of file app_originate.c.

◆ app_originate

const char app_originate[] = "Originate"
static

Definition at line 48 of file app_originate.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 334 of file app_originate.c.

◆ originate_exec_options

const struct ast_app_option originate_exec_options[128] = { [ 'a' ] = { .flag = OPT_ASYNC }, [ 'b' ] = { .flag = OPT_PREDIAL_CALLEE , .arg_index = OPT_ARG_PREDIAL_CALLEE + 1 }, [ 'B' ] = { .flag = OPT_PREDIAL_CALLER , .arg_index = OPT_ARG_PREDIAL_CALLER + 1 }, }
static

Definition at line 144 of file app_originate.c.

Referenced by originate_exec().