Wed Jan 8 2020 09:50:18

Asterisk developer's documentation


res_clioriginate.c File Reference

Originate calls via the CLI. More...

#include "asterisk.h"
#include "asterisk/channel.h"
#include "asterisk/pbx.h"
#include "asterisk/module.h"
#include "asterisk/cli.h"
#include "asterisk/utils.h"
#include "asterisk/frame.h"

Go to the source code of this file.

Macros

#define TIMEOUT   30
 

Functions

static void __reg_module (void)
 
static void __unreg_module (void)
 
 ASTERISK_FILE_VERSION (__FILE__,"$Revision: 361471 $")
 
static char * handle_orig (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 handle for orgination app or exten. More...
 
static char * handle_redirect (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 
static int load_module (void)
 
static char * orig_app (int fd, const char *chan, const char *app, const char *appdata)
 orginate a call from the CLI More...
 
static char * orig_exten (int fd, const char *chan, const char *data)
 orginate from extension More...
 
static int unload_module (void)
 

Variables

static struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_LOAD_ORDER , .description = "Call origination and redirection from the CLI" , .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 struct ast_module_infoast_module_info = &__mod_info
 
static struct ast_cli_entry cli_cliorig []
 

Detailed Description

Originate calls via the CLI.

Author
Russell Bryant russe.nosp@m.ll@d.nosp@m.igium.nosp@m..com

Definition in file res_clioriginate.c.

Macro Definition Documentation

#define TIMEOUT   30

The timeout for originated calls, in seconds

Definition at line 43 of file res_clioriginate.c.

Referenced by orig_app(), and orig_exten().

Function Documentation

static void __reg_module ( void  )
static

Definition at line 243 of file res_clioriginate.c.

static void __unreg_module ( void  )
static

Definition at line 243 of file res_clioriginate.c.

ASTERISK_FILE_VERSION ( __FILE__  ,
"$Revision: 361471 $"   
)
static char* handle_orig ( struct ast_cli_entry e,
int  cmd,
struct ast_cli_args a 
)
static

handle for orgination app or exten.

Parameters
epointer to the CLI structure to initialize
cmdoperation to execute
astructure that contains either application or extension arguments
Return values
CLI_SUCCESSon success.
CLI_SHOWUSAGEon failure.

Definition at line 122 of file res_clioriginate.c.

References ast_cli_args::argv, ast_cli_complete(), ast_complete_applications(), ast_module_ref(), ast_module_unref(), ast_strlen_zero(), CLI_GENERATE, CLI_INIT, CLI_SHOWUSAGE, ast_cli_entry::command, ast_cli_args::fd, ast_cli_args::line, ast_cli_args::n, orig_app(), orig_exten(), ast_cli_args::pos, ast_module_info::self, ast_cli_entry::usage, and ast_cli_args::word.

123 {
124  static const char * const choices[] = { "application", "extension", NULL };
125  char *res = NULL;
126  switch (cmd) {
127  case CLI_INIT:
128  e->command = "channel originate";
129  e->usage =
130  " There are two ways to use this command. A call can be originated between a\n"
131  "channel and a specific application, or between a channel and an extension in\n"
132  "the dialplan. This is similar to call files or the manager originate action.\n"
133  "Calls originated with this command are given a timeout of 30 seconds.\n\n"
134 
135  "Usage1: channel originate <tech/data> application <appname> [appdata]\n"
136  " This will originate a call between the specified channel tech/data and the\n"
137  "given application. Arguments to the application are optional. If the given\n"
138  "arguments to the application include spaces, all of the arguments to the\n"
139  "application need to be placed in quotation marks.\n\n"
140 
141  "Usage2: channel originate <tech/data> extension [exten@][context]\n"
142  " This will originate a call between the specified channel tech/data and the\n"
143  "given extension. If no context is specified, the 'default' context will be\n"
144  "used. If no extension is given, the 's' extension will be used.\n";
145  return NULL;
146  case CLI_GENERATE:
147  /* ugly, can be removed when CLI entries have ast_module pointers */
149  if (a->pos == 3) {
150  res = ast_cli_complete(a->word, choices, a->n);
151  } else if (a->pos == 4) {
152  if (!strcasecmp("application", a->argv[3])) {
153  res = ast_complete_applications(a->line, a->word, a->n);
154  }
155  }
157  return res;
158  }
159 
160  if (ast_strlen_zero(a->argv[2]) || ast_strlen_zero(a->argv[3]))
161  return CLI_SHOWUSAGE;
162 
163  /* ugly, can be removed when CLI entries have ast_module pointers */
165 
166  if (!strcasecmp("application", a->argv[3])) {
167  res = orig_app(a->fd, a->argv[2], a->argv[4], a->argv[5]);
168  } else if (!strcasecmp("extension", a->argv[3])) {
169  res = orig_exten(a->fd, a->argv[2], a->argv[4]);
170  } else {
171  res = CLI_SHOWUSAGE;
172  }
173 
175 
176  return res;
177 }
void ast_module_unref(struct ast_module *)
Definition: loader.c:1312
char * ast_complete_applications(const char *line, const char *word, int state)
Command completion for the list of installed applications.
Definition: pbx.c:11336
Definition: cli.h:146
static char * orig_app(int fd, const char *chan, const char *app, const char *appdata)
orginate a call from the CLI
const char * line
Definition: cli.h:156
char * ast_cli_complete(const char *word, const char *const choices[], int pos)
Definition: cli.c:1535
struct ast_module * self
Definition: module.h:227
const int fd
Definition: cli.h:153
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition: strings.h:63
const int n
Definition: cli.h:159
static char * orig_exten(int fd, const char *chan, const char *data)
orginate from extension
const char *const * argv
Definition: cli.h:155
#define CLI_SHOWUSAGE
Definition: cli.h:44
char * command
Definition: cli.h:180
const char * word
Definition: cli.h:157
const char * usage
Definition: cli.h:171
const int pos
Definition: cli.h:158
struct ast_module * ast_module_ref(struct ast_module *)
Definition: loader.c:1300
static char* handle_redirect ( struct ast_cli_entry e,
int  cmd,
struct ast_cli_args a 
)
static
Todo:
It would be nice to be able to redirect 2 channels at the same time like you can with AMI redirect. However, it is not possible to acquire two channels without the potential for a deadlock with how ast_channel structs are managed today. Once ast_channel is a refcounted object, this command will be able to support that.

Definition at line 179 of file res_clioriginate.c.

References ast_cli_args::argc, ast_cli_entry::args, ast_cli_args::argv, ast_async_parseable_goto(), ast_channel_get_by_name(), ast_channel_unref, ast_cli(), ast_complete_channels(), CLI_FAILURE, CLI_GENERATE, CLI_INIT, CLI_SHOWUSAGE, CLI_SUCCESS, ast_cli_entry::command, ast_cli_args::fd, ast_cli_args::line, ast_cli_args::n, name, ast_cli_args::pos, ast_cli_entry::usage, and ast_cli_args::word.

180 {
181  const char *name, *dest;
182  struct ast_channel *chan;
183  int res;
184 
185  switch (cmd) {
186  case CLI_INIT:
187  e->command = "channel redirect";
188  e->usage = ""
189  "Usage: channel redirect <channel> <[[context,]exten,]priority>\n"
190  " Redirect an active channel to a specified extension.\n";
191  /*! \todo It would be nice to be able to redirect 2 channels at the same
192  * time like you can with AMI redirect. However, it is not possible to acquire
193  * two channels without the potential for a deadlock with how ast_channel structs
194  * are managed today. Once ast_channel is a refcounted object, this command
195  * will be able to support that. */
196  return NULL;
197  case CLI_GENERATE:
198  return ast_complete_channels(a->line, a->word, a->pos, a->n, 2);
199  }
200 
201  if (a->argc != e->args + 2) {
202  return CLI_SHOWUSAGE;
203  }
204 
205  name = a->argv[2];
206  dest = a->argv[3];
207 
208  if (!(chan = ast_channel_get_by_name(name))) {
209  ast_cli(a->fd, "Channel '%s' not found\n", name);
210  return CLI_FAILURE;
211  }
212 
213  res = ast_async_parseable_goto(chan, dest);
214 
215  chan = ast_channel_unref(chan);
216 
217  if (!res) {
218  ast_cli(a->fd, "Channel '%s' successfully redirected to %s\n", name, dest);
219  } else {
220  ast_cli(a->fd, "Channel '%s' failed to be redirected to %s\n", name, dest);
221  }
222 
223  return res ? CLI_FAILURE : CLI_SUCCESS;
224 }
Main Channel structure associated with a channel.
Definition: channel.h:742
#define ast_channel_unref(c)
Decrease channel reference count.
Definition: channel.h:2502
const int argc
Definition: cli.h:154
Definition: cli.h:146
void ast_cli(int fd, const char *fmt,...)
Definition: cli.c:105
const char * line
Definition: cli.h:156
int args
This gets set in ast_cli_register()
Definition: cli.h:179
const int fd
Definition: cli.h:153
const int n
Definition: cli.h:159
const char *const * argv
Definition: cli.h:155
#define CLI_SHOWUSAGE
Definition: cli.h:44
#define CLI_FAILURE
Definition: cli.h:45
static const char name[]
char * command
Definition: cli.h:180
const char * word
Definition: cli.h:157
const char * usage
Definition: cli.h:171
int ast_async_parseable_goto(struct ast_channel *chan, const char *goto_string)
Definition: pbx.c:11331
#define CLI_SUCCESS
Definition: cli.h:43
const int pos
Definition: cli.h:158
char * ast_complete_channels(const char *line, const char *word, int pos, int state, int rpos)
Command completion for the list of active channels.
Definition: cli.c:1547
struct ast_channel * ast_channel_get_by_name(const char *name)
Find a channel by name.
Definition: channel.c:1803
static int load_module ( void  )
static

Definition at line 236 of file res_clioriginate.c.

References ARRAY_LEN, ast_cli_register_multiple(), AST_MODULE_LOAD_DECLINE, and AST_MODULE_LOAD_SUCCESS.

237 {
238  int res;
241 }
#define ARRAY_LEN(a)
Definition: isdn_lib.c:42
static struct ast_cli_entry cli_cliorig[]
int ast_cli_register_multiple(struct ast_cli_entry *e, int len)
Register multiple commands.
Definition: cli.c:2167
static char* orig_app ( int  fd,
const char *  chan,
const char *  app,
const char *  appdata 
)
static

orginate a call from the CLI

Parameters
fdfile descriptor for cli
chanchannel to create type/data
appapplication you want to run
appdatadata for application
Return values
CLI_SUCCESSon success.
CLI_SHOWUSAGEon failure.

Definition at line 54 of file res_clioriginate.c.

References ast_cli(), AST_FORMAT_SLINEAR, ast_pbx_outgoing_app(), ast_strdupa, ast_strlen_zero(), CLI_SHOWUSAGE, CLI_SUCCESS, strsep(), and TIMEOUT.

Referenced by handle_orig().

55 {
56  char *chantech;
57  char *chandata;
58  int reason = 0;
59 
60  if (ast_strlen_zero(app))
61  return CLI_SHOWUSAGE;
62 
63  chandata = ast_strdupa(chan);
64 
65  chantech = strsep(&chandata, "/");
66  if (!chandata) {
67  ast_cli(fd, "*** No data provided after channel type! ***\n");
68  return CLI_SHOWUSAGE;
69  }
70 
71  ast_pbx_outgoing_app(chantech, AST_FORMAT_SLINEAR, chandata, TIMEOUT * 1000, app, appdata, &reason, 0, NULL, NULL, NULL, NULL, NULL);
72 
73  return CLI_SUCCESS;
74 }
char * strsep(char **str, const char *delims)
#define TIMEOUT
void ast_cli(int fd, const char *fmt,...)
Definition: cli.c:105
static const char app[]
Definition: app_adsiprog.c:49
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition: strings.h:63
#define ast_strdupa(s)
duplicate a string in memory from the stack
Definition: utils.h:663
#define CLI_SHOWUSAGE
Definition: cli.h:44
#define CLI_SUCCESS
Definition: cli.h:43
#define AST_FORMAT_SLINEAR
Definition: frame.h:254
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 char* orig_exten ( int  fd,
const char *  chan,
const char *  data 
)
static

orginate from extension

Parameters
fdfile descriptor for cli
chanchannel to create type/data
datacontains exten@context
Return values
CLI_SUCCESSon success.
CLI_SHOWUSAGEon failure.

Definition at line 84 of file res_clioriginate.c.

References ast_cli(), AST_FORMAT_SLINEAR, ast_pbx_outgoing_exten(), ast_strdupa, ast_strlen_zero(), CLI_SHOWUSAGE, CLI_SUCCESS, context, exten, strsep(), and TIMEOUT.

Referenced by gosub_exec(), handle_orig(), and park_call_exec().

85 {
86  char *chantech;
87  char *chandata;
88  char *exten = NULL;
89  char *context = NULL;
90  int reason = 0;
91 
92  chandata = ast_strdupa(chan);
93 
94  chantech = strsep(&chandata, "/");
95  if (!chandata) {
96  ast_cli(fd, "*** No data provided after channel type! ***\n");
97  return CLI_SHOWUSAGE;
98  }
99 
100  if (!ast_strlen_zero(data)) {
101  context = ast_strdupa(data);
102  exten = strsep(&context, "@");
103  }
104 
105  if (ast_strlen_zero(exten))
106  exten = "s";
107  if (ast_strlen_zero(context))
108  context = "default";
109 
110  ast_pbx_outgoing_exten(chantech, AST_FORMAT_SLINEAR, chandata, TIMEOUT * 1000, context, exten, 1, &reason, 0, NULL, NULL, NULL, NULL, NULL);
111 
112  return CLI_SUCCESS;
113 }
static char exten[AST_MAX_EXTENSION]
Definition: chan_alsa.c:109
char * strsep(char **str, const char *delims)
#define TIMEOUT
const char * data
Definition: channel.h:755
void ast_cli(int fd, const char *fmt,...)
Definition: cli.c:105
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition: strings.h:63
#define ast_strdupa(s)
duplicate a string in memory from the stack
Definition: utils.h:663
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
#define CLI_SHOWUSAGE
Definition: cli.h:44
#define CLI_SUCCESS
Definition: cli.h:43
#define AST_FORMAT_SLINEAR
Definition: frame.h:254
static char context[AST_MAX_CONTEXT]
Definition: chan_alsa.c:107
static int unload_module ( void  )
static

Definition at line 231 of file res_clioriginate.c.

References ARRAY_LEN, and ast_cli_unregister_multiple().

232 {
234 }
#define ARRAY_LEN(a)
Definition: isdn_lib.c:42
int ast_cli_unregister_multiple(struct ast_cli_entry *e, int len)
Unregister multiple commands.
Definition: cli.c:2177
static struct ast_cli_entry cli_cliorig[]

Variable Documentation

struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_LOAD_ORDER , .description = "Call origination and redirection from the CLI" , .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 243 of file res_clioriginate.c.

Definition at line 243 of file res_clioriginate.c.

struct ast_cli_entry cli_cliorig[]
static
Initial value:
= {
AST_CLI_DEFINE(handle_orig, "Originate a call"),
AST_CLI_DEFINE(handle_redirect, "Redirect a call"),
}
#define AST_CLI_DEFINE(fn, txt,...)
Definition: cli.h:191
static char * handle_orig(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
handle for orgination app or exten.
static char * handle_redirect(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)

Definition at line 226 of file res_clioriginate.c.