Thu Apr 28 2011 17:16:17

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
__MODULE_INFO_SECTION 
__mod_info = { __MODULE_INFO_GLOBALS .name = AST_MODULE, .flags = AST_MODFLAG_DEFAULT , .description = "Call origination and redirection from the CLI" , .key = ASTERISK_GPL_KEY , .buildopt_sum = AST_BUILDOPT_SUM, .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(), and orig_exten().


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:
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 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_module_info::self, ast_cli_entry::usage, and ast_cli_args::word.

{
   static char *choices[] = { "application", "extension", NULL };
   char *res;
   switch (cmd) {
   case CLI_INIT:
      e->command = "channel originate";
      e->usage = 
         "  There are two ways to use this command. A call can be originated between a\n"
         "channel and a specific application, or between a channel and an extension in\n"
         "the dialplan. This is similar to call files or the manager originate action.\n"
         "Calls originated with this command are given a timeout of 30 seconds.\n\n"

         "Usage1: channel originate <tech/data> application <appname> [appdata]\n"
         "  This will originate a call between the specified channel tech/data and the\n"
         "given application. Arguments to the application are optional. If the given\n"
         "arguments to the application include spaces, all of the arguments to the\n"
         "application need to be placed in quotation marks.\n\n"

         "Usage2: channel originate <tech/data> extension [exten@][context]\n"
         "  This will originate a call between the specified channel tech/data and the\n"
         "given extension. If no context is specified, the 'default' context will be\n"
         "used. If no extension is given, the 's' extension will be used.\n";
      return NULL;
   case CLI_GENERATE:
      if (a->pos != 3)
         return NULL;

      /* ugly, can be removed when CLI entries have ast_module pointers */
      ast_module_ref(ast_module_info->self);
      res = ast_cli_complete(a->word, choices, a->n);
      ast_module_unref(ast_module_info->self);

      return res;
   }

   if (ast_strlen_zero(a->argv[2]) || ast_strlen_zero(a->argv[3]))
      return CLI_SHOWUSAGE;

   /* ugly, can be removed when CLI entries have ast_module pointers */
   ast_module_ref(ast_module_info->self);

   if (!strcasecmp("application", a->argv[3])) {
      res = orig_app(a->fd, a->argv[2], a->argv[4], a->argv[5]);  
   } else if (!strcasecmp("extension", a->argv[3])) {
      res = orig_exten(a->fd, a->argv[2], a->argv[4]);
   } else {
      ast_log(LOG_WARNING, "else");
      res = CLI_SHOWUSAGE;
   }

   ast_module_unref(ast_module_info->self);

   return res;
}
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.

{
   const char *name, *dest;
   struct ast_channel *chan;
   int res;

   switch (cmd) {
   case CLI_INIT:
      e->command = "channel redirect";
      e->usage = ""
      "Usage: channel redirect <channel> <[[context,]exten,]priority>\n"
      "    Redirect an active channel to a specified extension.\n";
      /*! \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. */
      return NULL;
   case CLI_GENERATE:
      return ast_complete_channels(a->line, a->word, a->pos, a->n, 2);
   }

   if (a->argc != e->args + 2) {
      return CLI_SHOWUSAGE;
   }

   name = a->argv[2];
   dest = a->argv[3];

   chan = ast_get_channel_by_name_locked(name);
   if (!chan) {
      ast_cli(a->fd, "Channel '%s' not found\n", name);
      return CLI_FAILURE;
   }

   res = ast_async_parseable_goto(chan, dest);

   ast_channel_unlock(chan);

   if (!res) {
      ast_cli(a->fd, "Channel '%s' successfully redirected to %s\n", name, dest);
   } else {
      ast_cli(a->fd, "Channel '%s' failed to be redirected to %s\n", name, dest);
   }

   return res ? CLI_FAILURE : CLI_SUCCESS;
}
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:
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 50 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().

{
   char *chantech;
   char *chandata;
   int reason = 0;
   
   if (ast_strlen_zero(app))
      return CLI_SHOWUSAGE;

   chandata = ast_strdupa(chan);
   
   chantech = strsep(&chandata, "/");
   if (!chandata) {
      ast_cli(fd, "*** No data provided after channel type! ***\n");
      return CLI_SHOWUSAGE;
   }

   ast_pbx_outgoing_app(chantech, AST_FORMAT_SLINEAR, chandata, TIMEOUT * 1000, app, appdata, &reason, 0, NULL, NULL, NULL, NULL, NULL);

   return CLI_SUCCESS;
}
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 80 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 handle_orig(), and park_call_exec().

{
   char *chantech;
   char *chandata;
   char *exten = NULL;
   char *context = NULL;
   int reason = 0;

   chandata = ast_strdupa(chan);
   
   chantech = strsep(&chandata, "/");
   if (!chandata) {
      ast_cli(fd, "*** No data provided after channel type! ***\n");
      return CLI_SHOWUSAGE;
   }

   if (!ast_strlen_zero(data)) {
      context = ast_strdupa(data);
      exten = strsep(&context, "@");
   }

   if (ast_strlen_zero(exten))
      exten = "s";
   if (ast_strlen_zero(context))
      context = "default";
   
   ast_pbx_outgoing_exten(chantech, AST_FORMAT_SLINEAR, chandata, TIMEOUT * 1000, context, exten, 1, &reason, 0, NULL, NULL, NULL, NULL, NULL);

   return CLI_SUCCESS;
}
static int unload_module ( void  ) [static]

Variable Documentation

struct ast_module_info __MODULE_INFO_SECTION __mod_info = { __MODULE_INFO_GLOBALS .name = AST_MODULE, .flags = AST_MODFLAG_DEFAULT , .description = "Call origination and redirection from the CLI" , .key = ASTERISK_GPL_KEY , .buildopt_sum = AST_BUILDOPT_SUM, .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.