Wed Jan 8 2020 09:49:54

Asterisk developer's documentation


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"

Go to the source code of this file.

Functions

static void __reg_module (void)
 
static void __unreg_module (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 = "ac1f6a56484a8820659555499174e588" , .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_DEFAULT, }
 
static const char app_originate [] = "Originate"
 
static struct ast_module_infoast_module_info = &__mod_info
 

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.

Function Documentation

static void __reg_module ( void  )
static

Definition at line 220 of file app_originate.c.

static void __unreg_module ( void  )
static

Definition at line 220 of file app_originate.c.

static int load_module ( void  )
static

Definition at line 211 of file app_originate.c.

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

212 {
213  int res;
214 
216 
218 }
static int originate_exec(struct ast_channel *chan, const char *data)
Definition: app_originate.c:96
static const char app_originate[]
Definition: app_originate.c:49
#define ast_register_application_xml(app, execute)
Register an application using XML documentation.
Definition: module.h:437
static int originate_exec ( struct ast_channel chan,
const char *  data 
)
static

Definition at line 96 of file app_originate.c.

References args, AST_APP_ARG, 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_SLINEAR, ast_log(), ast_pbx_outgoing_app(), ast_pbx_outgoing_exten(), AST_STANDARD_APP_ARGS, ast_strdupa, ast_strlen_zero(), exten, LOG_ERROR, LOG_WARNING, parse(), pbx_builtin_setvar_helper(), S_OR, strsep(), and type.

Referenced by load_module().

97 {
99  AST_APP_ARG(tech_data);
100  AST_APP_ARG(type);
101  AST_APP_ARG(arg1);
102  AST_APP_ARG(arg2);
103  AST_APP_ARG(arg3);
104  );
105  char *parse;
106  char *chantech, *chandata;
107  int res = -1;
108  int outgoing_status = 0;
109  static const unsigned int timeout = 30;
110  static const char default_exten[] = "s";
111 
112  ast_autoservice_start(chan);
113 
114  if (ast_strlen_zero(data)) {
115  ast_log(LOG_ERROR, "Originate() requires arguments\n");
116  goto return_cleanup;
117  }
118 
119  parse = ast_strdupa(data);
120 
121  AST_STANDARD_APP_ARGS(args, parse);
122 
123  if (args.argc < 3) {
124  ast_log(LOG_ERROR, "Incorrect number of arguments\n");
125  goto return_cleanup;
126  }
127 
128  chandata = ast_strdupa(args.tech_data);
129  chantech = strsep(&chandata, "/");
130 
131  if (ast_strlen_zero(chandata) || ast_strlen_zero(chantech)) {
132  ast_log(LOG_ERROR, "Channel Tech/Data invalid: '%s'\n", args.tech_data);
133  goto return_cleanup;
134  }
135 
136  if (!strcasecmp(args.type, "exten")) {
137  int priority = 1; /* Initialized in case priority not specified */
138  const char *exten = args.arg2;
139 
140  if (args.argc == 5) {
141  /* Context/Exten/Priority all specified */
142  if (sscanf(args.arg3, "%30d", &priority) != 1) {
143  ast_log(LOG_ERROR, "Invalid priority: '%s'\n", args.arg3);
144  goto return_cleanup;
145  }
146  } else if (args.argc == 3) {
147  /* Exten not specified */
148  exten = default_exten;
149  }
150 
151  ast_debug(1, "Originating call to '%s/%s' and connecting them to extension %s,%s,%d\n",
152  chantech, chandata, args.arg1, exten, priority);
153 
154  ast_pbx_outgoing_exten(chantech, AST_FORMAT_SLINEAR, chandata,
155  timeout * 1000, args.arg1, exten, priority, &outgoing_status, 0, NULL,
156  NULL, NULL, NULL, NULL);
157  } else if (!strcasecmp(args.type, "app")) {
158  ast_debug(1, "Originating call to '%s/%s' and connecting them to %s(%s)\n",
159  chantech, chandata, args.arg1, S_OR(args.arg2, ""));
160 
161  ast_pbx_outgoing_app(chantech, AST_FORMAT_SLINEAR, chandata,
162  timeout * 1000, args.arg1, args.arg2, &outgoing_status, 0, NULL,
163  NULL, NULL, NULL, NULL);
164  } else {
165  ast_log(LOG_ERROR, "Incorrect type, it should be 'exten' or 'app': %s\n",
166  args.type);
167  goto return_cleanup;
168  }
169 
170  res = 0;
171 
172 return_cleanup:
173  if (res) {
174  pbx_builtin_setvar_helper(chan, "ORIGINATE_STATUS", "FAILED");
175  } else {
176  switch (outgoing_status) {
177  case 0:
178  case AST_CONTROL_ANSWER:
179  pbx_builtin_setvar_helper(chan, "ORIGINATE_STATUS", "SUCCESS");
180  break;
181  case AST_CONTROL_BUSY:
182  pbx_builtin_setvar_helper(chan, "ORIGINATE_STATUS", "BUSY");
183  break;
185  pbx_builtin_setvar_helper(chan, "ORIGINATE_STATUS", "CONGESTION");
186  break;
187  case AST_CONTROL_HANGUP:
188  pbx_builtin_setvar_helper(chan, "ORIGINATE_STATUS", "HANGUP");
189  break;
190  case AST_CONTROL_RINGING:
191  pbx_builtin_setvar_helper(chan, "ORIGINATE_STATUS", "RINGING");
192  break;
193  default:
194  ast_log(LOG_WARNING, "Unknown originate status result of '%d'\n",
195  outgoing_status);
196  pbx_builtin_setvar_helper(chan, "ORIGINATE_STATUS", "UNKNOWN");
197  break;
198  }
199  }
200 
201  ast_autoservice_stop(chan);
202 
203  return res;
204 }
static char exten[AST_MAX_EXTENSION]
Definition: chan_alsa.c:109
int ast_autoservice_start(struct ast_channel *chan)
Automatically service a channel for us...
Definition: autoservice.c:179
char * strsep(char **str, const char *delims)
#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
#define ast_debug(level,...)
Log a DEBUG message.
Definition: logger.h:236
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition: strings.h:63
int ast_autoservice_stop(struct ast_channel *chan)
Stop servicing a channel for us...
Definition: autoservice.c:238
#define ast_strdupa(s)
duplicate a string in memory from the stack
Definition: utils.h:663
#define LOG_ERROR
Definition: logger.h:155
int ast_pbx_outgoing_exten(const char *type, format_t format, void *data, int timeout, const char *context, const char *exten, int priority, int *reason, int sync, const char *cid_num, const char *cid_name, struct ast_variable *vars, const char *account, struct ast_channel **locked_channel)
Definition: pbx.c:9375
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
static void parse(struct mgcp_request *req)
Definition: chan_mgcp.c:1858
static const char type[]
Definition: chan_nbs.c:57
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
#define AST_FORMAT_SLINEAR
Definition: frame.h:254
#define S_OR(a, b)
returns the equivalent of logic or for strings: first one if not empty, otherwise second one...
Definition: strings.h:77
#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
int ast_pbx_outgoing_app(const char *type, format_t format, void *data, int timeout, const char *app, const char *appdata, int *reason, int sync, const char *cid_num, const char *cid_name, struct ast_variable *vars, const char *account, struct ast_channel **locked_channel)
Definition: pbx.c:9544
static int unload_module ( void  )
static

Definition at line 206 of file app_originate.c.

References ast_unregister_application().

207 {
209 }
int ast_unregister_application(const char *app)
Unregister an application.
Definition: pbx.c:7705
static const char app_originate[]
Definition: app_originate.c:49

Variable Documentation

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

Definition at line 220 of file app_originate.c.

const char app_originate[] = "Originate"
static

Definition at line 49 of file app_originate.c.

Definition at line 220 of file app_originate.c.