Asterisk - The Open Source Telephony Project GIT-master-27fb039
Loading...
Searching...
No Matches
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.
 
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
 
static char * orig_exten (int fd, const char *chan, const char *data)
 orginate from extension
 
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 = ASTERISK_GPL_KEY , .buildopt_sum = AST_BUILDOPT_SUM, .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.

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.

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}
#define CLI_SHOWUSAGE
Definition cli.h:45
char * ast_cli_complete(const char *word, const char *const choices[], int pos)
Definition main/cli.c:1823
@ CLI_INIT
Definition cli.h:152
@ CLI_GENERATE
Definition cli.h:153
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_exten(int fd, const char *chan, const char *data)
orginate from extension
static char * orig_app(int fd, const char *chan, const char *app, const char *appdata)
orginate a call from the CLI
#define NULL
Definition resample.c:96
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition strings.h:65
char * command
Definition cli.h:186
const char * usage
Definition cli.h:177
static struct test_val a

References a, ast_cli_complete(), ast_complete_applications(), ast_strlen_zero(), CLI_GENERATE, CLI_INIT, CLI_SHOWUSAGE, ast_cli_entry::command, NULL, orig_app(), orig_exten(), and ast_cli_entry::usage.

◆ 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.

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}
struct ast_channel * ast_channel_get_by_name(const char *search)
Find a channel by name or uniqueid.
Definition channel.c:1416
#define ast_channel_unref(c)
Decrease channel reference count.
Definition channel.h:3018
#define CLI_SUCCESS
Definition cli.h:44
void ast_cli(int fd, const char *fmt,...)
Definition clicompat.c:6
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:1842
#define CLI_FAILURE
Definition cli.h:46
static const char name[]
Definition format_mp3.c:68
int ast_async_parseable_goto(struct ast_channel *chan, const char *goto_string)
Definition pbx.c:8896
Main Channel structure associated with a channel.
int args
This gets set in ast_cli_register()
Definition cli.h:185

References a, ast_cli_entry::args, 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, name, NULL, and ast_cli_entry::usage.

◆ load_module()

static int load_module ( void  )
static

Definition at line 242 of file res_clioriginate.c.

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

References ARRAY_LEN, ast_cli_register_multiple, AST_MODULE_LOAD_DECLINE, AST_MODULE_LOAD_SUCCESS, and cli_cliorig.

◆ 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.

54{
55 char *chantech;
56 char *chandata;
57 int reason = 0;
58 struct ast_format_cap *cap;
59
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,
77 NULL, NULL);
78 ao2_ref(cap, -1);
79
80 return CLI_SUCCESS;
81}
static const char app[]
char * strsep(char **str, const char *delims)
#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
struct ast_format * ast_format_slin
Built-in cached signed linear 8kHz format.
@ AST_FORMAT_CAP_FLAG_DEFAULT
Definition format_cap.h:38
#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
@ AST_OUTGOING_NO_WAIT
Definition pbx.h:1143
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:8005
#define TIMEOUT
Format capabilities structure, holds formats + preference order + etc.
Definition format_cap.c:54

References ao2_ref, app, 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().

◆ 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.

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}
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:7941

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, NULL, strsep(), and TIMEOUT.

Referenced by gosub_exec(), and handle_orig().

◆ unload_module()

static int unload_module ( void  )
static

Definition at line 237 of file res_clioriginate.c.

238{
240}
void ast_cli_unregister_multiple(void)
Definition ael_main.c:408

References ARRAY_LEN, ast_cli_unregister_multiple(), and 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 = ASTERISK_GPL_KEY , .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 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_redirect(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
static char * handle_orig(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
handle for orgination app or exten.

Definition at line 232 of file res_clioriginate.c.

232 {
233 AST_CLI_DEFINE(handle_orig, "Originate a call"),
234 AST_CLI_DEFINE(handle_redirect, "Redirect a call"),
235};
#define AST_CLI_DEFINE(fn, txt,...)
Definition cli.h:197

Referenced by load_module(), and unload_module().