Asterisk - The Open Source Telephony Project  18.5.0
Macros | Functions | Variables
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"
#include "asterisk/format_cache.h"
Include dependency graph for res_clioriginate.c:

Go to the source code of this file.

Macros

#define TIMEOUT   30
 

Functions

static void __reg_module (void)
 
static void __unreg_module (void)
 
struct ast_moduleAST_MODULE_SELF_SYM (void)
 
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 = "30ef0c93b36035ec78c9cfd712d36d9b" , .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_DEFAULT, .support_level = AST_MODULE_SUPPORT_CORE, }
 
static const 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

◆ TIMEOUT

#define TIMEOUT   30

The timeout for originated calls, in seconds

Definition at line 42 of file res_clioriginate.c.

Referenced by orig_app(), and orig_exten().

Function Documentation

◆ __reg_module()

static void __reg_module ( void  )
static

Definition at line 249 of file res_clioriginate.c.

◆ __unreg_module()

static void __unreg_module ( void  )
static

Definition at line 249 of file res_clioriginate.c.

◆ AST_MODULE_SELF_SYM()

struct ast_module* AST_MODULE_SELF_SYM ( void  )

Definition at line 249 of file res_clioriginate.c.

◆ handle_orig()

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 136 of file res_clioriginate.c.

References ast_cli_args::argv, ast_cli_complete(), ast_complete_applications(), 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, NULL, orig_app(), orig_exten(), ast_cli_args::pos, ast_cli_entry::usage, and ast_cli_args::word.

137 {
138  static const char * const choices[] = { "application", "extension", NULL };
139  char *res = NULL;
140  switch (cmd) {
141  case CLI_INIT:
142  e->command = "channel originate";
143  e->usage =
144  " There are two ways to use this command. A call can be originated between a\n"
145  "channel and a specific application, or between a channel and an extension in\n"
146  "the dialplan. This is similar to call files or the manager originate action.\n"
147  "Calls originated with this command are given a timeout of 30 seconds.\n\n"
148 
149  "Usage1: channel originate <tech/data> application <appname> [appdata]\n"
150  " This will originate a call between the specified channel tech/data and the\n"
151  "given application. Arguments to the application are optional. If the given\n"
152  "arguments to the application include spaces, all of the arguments to the\n"
153  "application need to be placed in quotation marks.\n\n"
154 
155  "Usage2: channel originate <tech/data> extension [exten@][context]\n"
156  " This will originate a call between the specified channel tech/data and the\n"
157  "given extension. If no context is specified, the 'default' context will be\n"
158  "used. If no extension is given, the 's' extension will be used.\n";
159  return NULL;
160  case CLI_GENERATE:
161  if (a->pos == 3) {
162  res = ast_cli_complete(a->word, choices, a->n);
163  } else if (a->pos == 4) {
164  if (!strcasecmp("application", a->argv[3])) {
165  res = ast_complete_applications(a->line, a->word, a->n);
166  }
167  }
168  return res;
169  }
170 
171  if (ast_strlen_zero(a->argv[2]) || ast_strlen_zero(a->argv[3]))
172  return CLI_SHOWUSAGE;
173 
174  if (!strcasecmp("application", a->argv[3])) {
175  res = orig_app(a->fd, a->argv[2], a->argv[4], a->argv[5]);
176  } else if (!strcasecmp("extension", a->argv[3])) {
177  res = orig_exten(a->fd, a->argv[2], a->argv[4]);
178  } else {
179  res = CLI_SHOWUSAGE;
180  }
181 
182  return res;
183 }
char * ast_complete_applications(const char *line, const char *word, int state)
Command completion for the list of installed applications.
Definition: pbx_app.c:429
Definition: cli.h:152
#define NULL
Definition: resample.c:96
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:162
#define ast_strlen_zero(foo)
Definition: strings.h:52
char * ast_cli_complete(const char *word, const char *const choices[], int pos)
Definition: main/cli.c:1811
const int fd
Definition: cli.h:159
const int n
Definition: cli.h:165
static char * orig_exten(int fd, const char *chan, const char *data)
orginate from extension
const char *const * argv
Definition: cli.h:161
#define CLI_SHOWUSAGE
Definition: cli.h:45
char * command
Definition: cli.h:186
const char * word
Definition: cli.h:163
const char * usage
Definition: cli.h:177
const int pos
Definition: cli.h:164

◆ handle_redirect()

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 185 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, NULL, ast_cli_args::pos, ast_cli_entry::usage, and ast_cli_args::word.

186 {
187  const char *name, *dest;
188  struct ast_channel *chan;
189  int res;
190 
191  switch (cmd) {
192  case CLI_INIT:
193  e->command = "channel redirect";
194  e->usage = ""
195  "Usage: channel redirect <channel> <[[context,]exten,]priority>\n"
196  " Redirect an active channel to a specified extension.\n";
197  /*! \todo It would be nice to be able to redirect 2 channels at the same
198  * time like you can with AMI redirect. However, it is not possible to acquire
199  * two channels without the potential for a deadlock with how ast_channel structs
200  * are managed today. Once ast_channel is a refcounted object, this command
201  * will be able to support that. */
202  return NULL;
203  case CLI_GENERATE:
204  return ast_complete_channels(a->line, a->word, a->pos, a->n, 2);
205  }
206 
207  if (a->argc != e->args + 2) {
208  return CLI_SHOWUSAGE;
209  }
210 
211  name = a->argv[2];
212  dest = a->argv[3];
213 
214  if (!(chan = ast_channel_get_by_name(name))) {
215  ast_cli(a->fd, "Channel '%s' not found\n", name);
216  return CLI_FAILURE;
217  }
218 
219  res = ast_async_parseable_goto(chan, dest);
220 
221  chan = ast_channel_unref(chan);
222 
223  if (!res) {
224  ast_cli(a->fd, "Channel '%s' successfully redirected to %s\n", name, dest);
225  } else {
226  ast_cli(a->fd, "Channel '%s' failed to be redirected to %s\n", name, dest);
227  }
228 
229  return res ? CLI_FAILURE : CLI_SUCCESS;
230 }
Main Channel structure associated with a channel.
#define ast_channel_unref(c)
Decrease channel reference count.
Definition: channel.h:2981
const int argc
Definition: cli.h:160
Definition: cli.h:152
#define NULL
Definition: resample.c:96
void ast_cli(int fd, const char *fmt,...)
Definition: clicompat.c:6
const char * line
Definition: cli.h:162
int args
This gets set in ast_cli_register()
Definition: cli.h:185
const int fd
Definition: cli.h:159
const int n
Definition: cli.h:165
const char *const * argv
Definition: cli.h:161
#define CLI_SHOWUSAGE
Definition: cli.h:45
#define CLI_FAILURE
Definition: cli.h:46
static const char name[]
Definition: cdr_mysql.c:74
char * command
Definition: cli.h:186
const char * word
Definition: cli.h:163
const char * usage
Definition: cli.h:177
int ast_async_parseable_goto(struct ast_channel *chan, const char *goto_string)
Definition: pbx.c:8864
#define CLI_SUCCESS
Definition: cli.h:44
const int pos
Definition: cli.h:164
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: main/cli.c:1830
struct ast_channel * ast_channel_get_by_name(const char *name)
Find a channel by name.
Definition: channel.c:1454

◆ load_module()

static int load_module ( void  )
static

Definition at line 242 of file res_clioriginate.c.

References ARRAY_LEN, ast_cli_register_multiple, AST_MODULE_LOAD_DECLINE, and AST_MODULE_LOAD_SUCCESS.

243 {
244  int res;
247 }
#define ARRAY_LEN(a)
Definition: isdn_lib.c:42
#define ast_cli_register_multiple(e, len)
Register multiple commands.
Definition: cli.h:265
static struct ast_cli_entry cli_cliorig[]
Module has failed to load, may be in an inconsistent state.
Definition: module.h:78

◆ orig_app()

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 53 of file res_clioriginate.c.

References ao2_ref, ast_cli(), ast_format_cap_alloc, ast_format_cap_append, AST_FORMAT_CAP_FLAG_DEFAULT, ast_format_slin, AST_OUTGOING_NO_WAIT, ast_pbx_outgoing_app(), ast_strdupa, ast_strlen_zero, CLI_FAILURE, CLI_SHOWUSAGE, CLI_SUCCESS, NULL, strsep(), and TIMEOUT.

Referenced by handle_orig().

54 {
55  char *chantech;
56  char *chandata;
57  int reason = 0;
58  struct ast_format_cap *cap;
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 
72  return CLI_FAILURE;
73  }
75  ast_pbx_outgoing_app(chantech, cap, chandata, TIMEOUT * 1000, app, appdata,
76  &reason, AST_OUTGOING_NO_WAIT, NULL, NULL, NULL, NULL,
77  NULL, NULL);
78  ao2_ref(cap, -1);
79 
80  return CLI_SUCCESS;
81 }
#define TIMEOUT
#define NULL
Definition: resample.c:96
void ast_cli(int fd, const char *fmt,...)
Definition: clicompat.c:6
#define ast_strlen_zero(foo)
Definition: strings.h:52
#define ao2_ref(o, delta)
Definition: astobj2.h:464
#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
Format capabilities structure, holds formats + preference order + etc.
Definition: format_cap.c:54
#define CLI_SHOWUSAGE
Definition: cli.h:45
int ast_pbx_outgoing_app(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)
Synchronously or asynchronously make an outbound call and execute an application on the channel...
Definition: pbx.c:8015
#define CLI_FAILURE
Definition: cli.h:46
#define CLI_SUCCESS
Definition: cli.h:44
char * strsep(char **str, const char *delims)
static const char app[]
Definition: app_mysql.c:62
struct ast_format * ast_format_slin
Built-in cached signed linear 8kHz format.
Definition: format_cache.c:41

◆ orig_exten()

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 91 of file res_clioriginate.c.

References ao2_ref, ast_cli(), ast_format_cap_alloc, ast_format_cap_append, AST_FORMAT_CAP_FLAG_DEFAULT, ast_format_slin, AST_OUTGOING_NO_WAIT, ast_pbx_outgoing_exten(), ast_strdupa, ast_strlen_zero, CLI_FAILURE, CLI_SHOWUSAGE, CLI_SUCCESS, context, exten, NULL, strsep(), and TIMEOUT.

Referenced by gosub_exec(), and handle_orig().

92 {
93  char *chantech;
94  char *chandata;
95  char *exten = NULL;
96  char *context = NULL;
97  int reason = 0;
98  struct ast_format_cap *cap;
99 
100  chandata = ast_strdupa(chan);
101 
102  chantech = strsep(&chandata, "/");
103  if (!chandata) {
104  ast_cli(fd, "*** No data provided after channel type! ***\n");
105  return CLI_SHOWUSAGE;
106  }
107 
108  if (!ast_strlen_zero(data)) {
109  context = ast_strdupa(data);
110  exten = strsep(&context, "@");
111  }
112 
113  if (ast_strlen_zero(exten))
114  exten = "s";
115  if (ast_strlen_zero(context))
116  context = "default";
118  return CLI_FAILURE;
119  }
121  ast_pbx_outgoing_exten(chantech, cap, chandata, TIMEOUT * 1000, context,
122  exten, 1, &reason, AST_OUTGOING_NO_WAIT, NULL, NULL,
123  NULL, NULL, NULL, 0, NULL);
124  ao2_ref(cap, -1);
125 
126  return CLI_SUCCESS;
127 }
static char exten[AST_MAX_EXTENSION]
Definition: chan_alsa.c:118
#define TIMEOUT
#define NULL
Definition: resample.c:96
void ast_cli(int fd, const char *fmt,...)
Definition: clicompat.c:6
int ast_pbx_outgoing_exten(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)
Synchronously or asynchronously make an outbound call and send it to a particular extension...
Definition: pbx.c:7951
#define ast_strlen_zero(foo)
Definition: strings.h:52
#define ao2_ref(o, delta)
Definition: astobj2.h:464
#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
Format capabilities structure, holds formats + preference order + etc.
Definition: format_cap.c:54
#define CLI_SHOWUSAGE
Definition: cli.h:45
#define CLI_FAILURE
Definition: cli.h:46
#define CLI_SUCCESS
Definition: cli.h:44
char * strsep(char **str, const char *delims)
static char context[AST_MAX_CONTEXT]
Definition: chan_alsa.c:116
struct ast_format * ast_format_slin
Built-in cached signed linear 8kHz format.
Definition: format_cache.c:41

◆ unload_module()

static int unload_module ( void  )
static

Definition at line 237 of file res_clioriginate.c.

References ARRAY_LEN, and ast_cli_unregister_multiple().

238 {
240 }
#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: clicompat.c:30
static struct ast_cli_entry cli_cliorig[]

Variable Documentation

◆ __mod_info

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

Definition at line 249 of file res_clioriginate.c.

◆ ast_module_info

const struct ast_module_info* ast_module_info = &__mod_info
static

Definition at line 249 of file res_clioriginate.c.

◆ cli_cliorig

struct ast_cli_entry cli_cliorig[]
static
Initial value:
= {
{ .handler = handle_orig , .summary = "Originate a call" ,},
{ .handler = handle_redirect , .summary = "Redirect a call" ,},
}
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 232 of file res_clioriginate.c.