Fri Nov 12 12:07:44 2010

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"
Include dependency graph for res_clioriginate.c:

Go to the source code of this file.

Defines

#define TIMEOUT   30

Functions

static void __reg_module (void)
static void __unreg_module (void)
 ASTERISK_FILE_VERSION (__FILE__,"$Revision: 163828 $")
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_DEFAULT , .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 = "0901e4e500243c855563a2d78b0c03e4" , .load = load_module, .unload = unload_module, }
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 <russell@digium.com>

Definition in file res_clioriginate.c.


Define Documentation

#define TIMEOUT   30

The timeout for originated calls, in seconds

Definition at line 39 of file res_clioriginate.c.

Referenced by orig_app(), orig_exten(), rpt(), and rpt_tele_thread().


Function Documentation

static void __reg_module ( void   )  [static]

Definition at line 240 of file res_clioriginate.c.

static void __unreg_module ( void   )  [static]

Definition at line 240 of file res_clioriginate.c.

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

handle for orgination app or exten.

Parameters:
e pointer to the CLI structure to initialize
cmd operation to execute
a structure that contains either application or extension arguments
Return values:
CLI_SUCCESS on success.
CLI_SHOWUSAGE on failure.

Definition at line 119 of file res_clioriginate.c.

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

00120 {
00121    static char *choices[] = { "application", "extension", NULL };
00122    char *res;
00123    switch (cmd) {
00124    case CLI_INIT:
00125       e->command = "channel originate";
00126       e->usage = 
00127          "  There are two ways to use this command. A call can be originated between a\n"
00128          "channel and a specific application, or between a channel and an extension in\n"
00129          "the dialplan. This is similar to call files or the manager originate action.\n"
00130          "Calls originated with this command are given a timeout of 30 seconds.\n\n"
00131 
00132          "Usage1: channel originate <tech/data> application <appname> [appdata]\n"
00133          "  This will originate a call between the specified channel tech/data and the\n"
00134          "given application. Arguments to the application are optional. If the given\n"
00135          "arguments to the application include spaces, all of the arguments to the\n"
00136          "application need to be placed in quotation marks.\n\n"
00137 
00138          "Usage2: channel originate <tech/data> extension [exten@][context]\n"
00139          "  This will originate a call between the specified channel tech/data and the\n"
00140          "given extension. If no context is specified, the 'default' context will be\n"
00141          "used. If no extension is given, the 's' extension will be used.\n";
00142       return NULL;
00143    case CLI_GENERATE:
00144       if (a->pos != 3)
00145          return NULL;
00146 
00147       /* ugly, can be removed when CLI entries have ast_module pointers */
00148       ast_module_ref(ast_module_info->self);
00149       res = ast_cli_complete(a->word, choices, a->n);
00150       ast_module_unref(ast_module_info->self);
00151 
00152       return res;
00153    }
00154 
00155    if (ast_strlen_zero(a->argv[2]) || ast_strlen_zero(a->argv[3]))
00156       return CLI_SHOWUSAGE;
00157 
00158    /* ugly, can be removed when CLI entries have ast_module pointers */
00159    ast_module_ref(ast_module_info->self);
00160 
00161    if (!strcasecmp("application", a->argv[3])) {
00162       res = orig_app(a->fd, a->argv[2], a->argv[4], a->argv[5]);  
00163    } else if (!strcasecmp("extension", a->argv[3])) {
00164       res = orig_exten(a->fd, a->argv[2], a->argv[4]);
00165    } else {
00166       ast_log(LOG_WARNING, "else");
00167       res = CLI_SHOWUSAGE;
00168    }
00169 
00170    ast_module_unref(ast_module_info->self);
00171 
00172    return res;
00173 }

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

References ast_cli_args::argc, ast_cli_entry::args, ast_cli_args::argv, ast_async_parseable_goto(), ast_channel_unlock, ast_cli(), ast_complete_channels(), ast_get_channel_by_name_locked(), chan, 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.

00176 {
00177    const char *name, *dest;
00178    struct ast_channel *chan;
00179    int res;
00180 
00181    switch (cmd) {
00182    case CLI_INIT:
00183       e->command = "channel redirect";
00184       e->usage = ""
00185       "Usage: channel redirect <channel> <[[context,]exten,]priority>\n"
00186       "    Redirect an active channel to a specified extension.\n";
00187       /*! \todo It would be nice to be able to redirect 2 channels at the same
00188        *  time like you can with AMI redirect.  However, it is not possible to acquire
00189        *  two channels without the potential for a deadlock with how ast_channel structs
00190        *  are managed today.  Once ast_channel is a refcounted object, this command
00191        *  will be able to support that. */
00192       return NULL;
00193    case CLI_GENERATE:
00194       return ast_complete_channels(a->line, a->word, a->pos, a->n, 2);
00195    }
00196 
00197    if (a->argc != e->args + 2) {
00198       return CLI_SHOWUSAGE;
00199    }
00200 
00201    name = a->argv[2];
00202    dest = a->argv[3];
00203 
00204    chan = ast_get_channel_by_name_locked(name);
00205    if (!chan) {
00206       ast_cli(a->fd, "Channel '%s' not found\n", name);
00207       return CLI_FAILURE;
00208    }
00209 
00210    res = ast_async_parseable_goto(chan, dest);
00211 
00212    ast_channel_unlock(chan);
00213 
00214    if (!res) {
00215       ast_cli(a->fd, "Channel '%s' successfully redirected to %s\n", name, dest);
00216    } else {
00217       ast_cli(a->fd, "Channel '%s' failed to be redirected to %s\n", name, dest);
00218    }
00219 
00220    return res ? CLI_FAILURE : CLI_SUCCESS;
00221 }

static int load_module ( void   )  [static]
static char* orig_app ( int  fd,
const char *  chan,
const char *  app,
const char *  appdata 
) [static]

orginate a call from the CLI

Parameters:
fd file descriptor for cli
chan channel to create type/data
app application you want to run
appdata data for application
Return values:
CLI_SUCCESS on success.
CLI_SHOWUSAGE on failure.

Definition at line 50 of file res_clioriginate.c.

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

Referenced by handle_orig().

00051 {
00052    char *chantech;
00053    char *chandata;
00054    int reason = 0;
00055    
00056    if (ast_strlen_zero(app))
00057       return CLI_SHOWUSAGE;
00058 
00059    chandata = ast_strdupa(chan);
00060    
00061    chantech = strsep(&chandata, "/");
00062    if (!chandata) {
00063       ast_cli(fd, "*** No data provided after channel type! ***\n");
00064       return CLI_SHOWUSAGE;
00065    }
00066 
00067    ast_pbx_outgoing_app(chantech, AST_FORMAT_SLINEAR, chandata, TIMEOUT * 1000, app, appdata, &reason, 0, NULL, NULL, NULL, NULL, NULL);
00068 
00069    return CLI_SUCCESS;
00070 }

static char* orig_exten ( int  fd,
const char *  chan,
const char *  data 
) [static]

orginate from extension

Parameters:
fd file descriptor for cli
chan channel to create type/data
data contains exten@context
Return values:
CLI_SUCCESS on success.
CLI_SHOWUSAGE on failure.

Definition at line 80 of file res_clioriginate.c.

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

Referenced by handle_orig(), and park_call_exec().

00081 {
00082    char *chantech;
00083    char *chandata;
00084    char *exten = NULL;
00085    char *context = NULL;
00086    int reason = 0;
00087 
00088    chandata = ast_strdupa(chan);
00089    
00090    chantech = strsep(&chandata, "/");
00091    if (!chandata) {
00092       ast_cli(fd, "*** No data provided after channel type! ***\n");
00093       return CLI_SHOWUSAGE;
00094    }
00095 
00096    if (!ast_strlen_zero(data)) {
00097       context = ast_strdupa(data);
00098       exten = strsep(&context, "@");
00099    }
00100 
00101    if (ast_strlen_zero(exten))
00102       exten = "s";
00103    if (ast_strlen_zero(context))
00104       context = "default";
00105    
00106    ast_pbx_outgoing_exten(chantech, AST_FORMAT_SLINEAR, chandata, TIMEOUT * 1000, context, exten, 1, &reason, 0, NULL, NULL, NULL, NULL, NULL);
00107 
00108    return CLI_SUCCESS;
00109 }

static int unload_module ( void   )  [static]

Definition at line 228 of file res_clioriginate.c.

References ARRAY_LEN, and ast_cli_unregister_multiple().


Variable Documentation

struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_DEFAULT , .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 = "0901e4e500243c855563a2d78b0c03e4" , .load = load_module, .unload = unload_module, } [static]

Definition at line 240 of file res_clioriginate.c.

Definition at line 240 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"),
}

Definition at line 223 of file res_clioriginate.c.


Generated by  doxygen 1.6.2