Mon Mar 12 2012 21:24:02

Asterisk developer's documentation


app_originate.c File Reference

Originate application. More...

#include "asterisk.h"
#include "asterisk/file.h"
#include "asterisk/channel.h"
#include "asterisk/pbx.h"
#include "asterisk/module.h"
#include "asterisk/app.h"
Include dependency graph for app_originate.c:

Go to the source code of this file.

Functions

static void __reg_module (void)
static void __unreg_module (void)
static int load_module (void)
static int originate_exec (struct ast_channel *chan, const char *data)
static int unload_module (void)

Variables

static struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_LOAD_ORDER , .description = "Originate call" , .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 = AST_BUILDOPT_SUM, .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_DEFAULT, }
static const char app_originate [] = "Originate"
static struct ast_module_infoast_module_info = &__mod_info

Detailed Description

Originate application.

Author:
Roberto Casas <roberto.casas@diaple.com>
Russell Bryant <russell@digium.com>
Todo:
Make a way to be able to set variables (and functions) on the outbound channel, similar to the Variable headers for the AMI Originate, and the Set options for call files.

Definition in file app_originate.c.


Function Documentation

static void __reg_module ( void  ) [static]

Definition at line 220 of file app_originate.c.

static void __unreg_module ( void  ) [static]

Definition at line 220 of file app_originate.c.

static int load_module ( void  ) [static]
static int originate_exec ( struct ast_channel chan,
const char *  data 
) [static]

Definition at line 96 of file app_originate.c.

References args, AST_APP_ARG, ast_autoservice_start(), ast_autoservice_stop(), AST_CONTROL_ANSWER, AST_CONTROL_BUSY, AST_CONTROL_CONGESTION, AST_CONTROL_HANGUP, AST_CONTROL_RINGING, ast_debug, AST_DECLARE_APP_ARGS, AST_FORMAT_SLINEAR, ast_log(), ast_pbx_outgoing_app(), ast_pbx_outgoing_exten(), AST_STANDARD_APP_ARGS, ast_strdupa, ast_strlen_zero(), exten, LOG_ERROR, LOG_WARNING, parse(), pbx_builtin_setvar_helper(), S_OR, strsep(), and type.

Referenced by load_module().

{
   AST_DECLARE_APP_ARGS(args,
      AST_APP_ARG(tech_data);
      AST_APP_ARG(type);
      AST_APP_ARG(arg1);
      AST_APP_ARG(arg2);
      AST_APP_ARG(arg3);
   );
   char *parse;
   char *chantech, *chandata;
   int res = -1;
   int outgoing_status = 0;
   static const unsigned int timeout = 30;
   static const char default_exten[] = "s";

   ast_autoservice_start(chan);

   if (ast_strlen_zero(data)) {
      ast_log(LOG_ERROR, "Originate() requires arguments\n");
      goto return_cleanup;
   }

   parse = ast_strdupa(data);

   AST_STANDARD_APP_ARGS(args, parse);

   if (args.argc < 3) {
      ast_log(LOG_ERROR, "Incorrect number of arguments\n");
      goto return_cleanup;
   }

   chandata = ast_strdupa(args.tech_data);
   chantech = strsep(&chandata, "/");

   if (ast_strlen_zero(chandata) || ast_strlen_zero(chantech)) {
      ast_log(LOG_ERROR, "Channel Tech/Data invalid: '%s'\n", args.tech_data);
      goto return_cleanup;
   }

   if (!strcasecmp(args.type, "exten")) {
      int priority = 1; /* Initialized in case priority not specified */
      const char *exten = args.arg2;

      if (args.argc == 5) {
         /* Context/Exten/Priority all specified */
         if (sscanf(args.arg3, "%30d", &priority) != 1) {
            ast_log(LOG_ERROR, "Invalid priority: '%s'\n", args.arg3);
            goto return_cleanup;
         }
      } else if (args.argc == 3) {
         /* Exten not specified */
         exten = default_exten;
      }

      ast_debug(1, "Originating call to '%s/%s' and connecting them to extension %s,%s,%d\n",
            chantech, chandata, args.arg1, exten, priority);

      ast_pbx_outgoing_exten(chantech, AST_FORMAT_SLINEAR, chandata,
            timeout * 1000, args.arg1, exten, priority, &outgoing_status, 0, NULL,
            NULL, NULL, NULL, NULL);
   } else if (!strcasecmp(args.type, "app")) {
      ast_debug(1, "Originating call to '%s/%s' and connecting them to %s(%s)\n",
            chantech, chandata, args.arg1, S_OR(args.arg2, ""));

      ast_pbx_outgoing_app(chantech, AST_FORMAT_SLINEAR, chandata,
            timeout * 1000, args.arg1, args.arg2, &outgoing_status, 0, NULL,
            NULL, NULL, NULL, NULL);
   } else {
      ast_log(LOG_ERROR, "Incorrect type, it should be 'exten' or 'app': %s\n",
            args.type);
      goto return_cleanup;
   }

   res = 0;

return_cleanup:
   if (res) {
      pbx_builtin_setvar_helper(chan, "ORIGINATE_STATUS", "FAILED");
   } else {
      switch (outgoing_status) {
      case 0:
      case AST_CONTROL_ANSWER:
         pbx_builtin_setvar_helper(chan, "ORIGINATE_STATUS", "SUCCESS");
         break;
      case AST_CONTROL_BUSY:
         pbx_builtin_setvar_helper(chan, "ORIGINATE_STATUS", "BUSY");
         break;
      case AST_CONTROL_CONGESTION:
         pbx_builtin_setvar_helper(chan, "ORIGINATE_STATUS", "CONGESTION");
         break;
      case AST_CONTROL_HANGUP:
         pbx_builtin_setvar_helper(chan, "ORIGINATE_STATUS", "HANGUP");
         break;
      case AST_CONTROL_RINGING:
         pbx_builtin_setvar_helper(chan, "ORIGINATE_STATUS", "RINGING");
         break;
      default:
         ast_log(LOG_WARNING, "Unknown originate status result of '%d'\n",
               outgoing_status);
         pbx_builtin_setvar_helper(chan, "ORIGINATE_STATUS", "UNKNOWN");
         break;
      }
   }

   ast_autoservice_stop(chan);

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

Definition at line 206 of file app_originate.c.

References ast_unregister_application().


Variable Documentation

struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_LOAD_ORDER , .description = "Originate call" , .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 = AST_BUILDOPT_SUM, .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_DEFAULT, } [static]

Definition at line 220 of file app_originate.c.

const char app_originate[] = "Originate" [static]

Definition at line 49 of file app_originate.c.

Definition at line 220 of file app_originate.c.