Asterisk - The Open Source Telephony Project  21.4.1
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"

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 = "da6642af068ee5e6490c5b1d2cc1d238" , .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

#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

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_complete(), ast_complete_applications(), ast_cli_entry::command, orig_app(), orig_exten(), and ast_cli_entry::usage.

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
static char * orig_app(int fd, const char *chan, const char *app, const char *appdata)
orginate a call from the CLI
char * ast_cli_complete(const char *word, const char *const choices[], int pos)
Definition: main/cli.c:1846
static char * orig_exten(int fd, const char *chan, const char *data)
orginate from extension
char * command
Definition: cli.h:186
const char * usage
Definition: cli.h:177
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_entry::args, ast_async_parseable_goto(), ast_channel_get_by_name(), ast_channel_unref, ast_complete_channels(), ast_cli_entry::command, and ast_cli_entry::usage.

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:2958
int args
This gets set in ast_cli_register()
Definition: cli.h:185
char * command
Definition: cli.h:186
const char * usage
Definition: cli.h:177
int ast_async_parseable_goto(struct ast_channel *chan, const char *goto_string)
Definition: pbx.c:8871
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:1865
struct ast_channel * ast_channel_get_by_name(const char *name)
Find a channel by name.
Definition: channel.c:1454
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_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, 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 ast_strdupa(s)
duplicate a string in memory from the stack
Definition: astmm.h:298
#define ao2_ref(o, delta)
Reference/unreference an object and return the old refcount.
Definition: astobj2.h:459
#define ast_format_cap_append(cap, format, framing)
Add format capability to capabilities structure.
Definition: format_cap.h:99
#define ast_format_cap_alloc(flags)
Allocate a new ast_format_cap structure.
Definition: format_cap.h:49
Format capabilities structure, holds formats + preference order + etc.
Definition: format_cap.c:54
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:7980
struct ast_format * ast_format_slin
Built-in cached signed linear 8kHz format.
Definition: format_cache.c:41
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_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, and TIMEOUT.

Referenced by 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 }
#define TIMEOUT
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:7916
#define ast_strdupa(s)
duplicate a string in memory from the stack
Definition: astmm.h:298
#define ao2_ref(o, delta)
Reference/unreference an object and return the old refcount.
Definition: astobj2.h:459
#define ast_format_cap_append(cap, format, framing)
Add format capability to capabilities structure.
Definition: format_cap.h:99
#define ast_format_cap_alloc(flags)
Allocate a new ast_format_cap structure.
Definition: format_cap.h:49
Format capabilities structure, holds formats + preference order + etc.
Definition: format_cap.c:54
struct ast_format * ast_format_slin
Built-in cached signed linear 8kHz format.
Definition: format_cache.c:41

Variable Documentation

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.