Wed Apr 6 11:29:50 2011

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"

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 = "8586c2a7d357cb591cc3a6607a8f62d1" , .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 217 of file app_originate.c.

static void __unreg_module ( void   )  [static]

Definition at line 217 of file app_originate.c.

static int load_module ( void   )  [static]

Definition at line 208 of file app_originate.c.

References AST_MODULE_LOAD_DECLINE, AST_MODULE_LOAD_SUCCESS, ast_register_application_xml, and originate_exec().

00209 {
00210    int res;
00211 
00212    res = ast_register_application_xml(app_originate, originate_exec);
00213 
00214    return res ? AST_MODULE_LOAD_DECLINE : AST_MODULE_LOAD_SUCCESS;
00215 }

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

Definition at line 92 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().

00093 {
00094    AST_DECLARE_APP_ARGS(args,
00095       AST_APP_ARG(tech_data);
00096       AST_APP_ARG(type);
00097       AST_APP_ARG(arg1);
00098       AST_APP_ARG(arg2);
00099       AST_APP_ARG(arg3);
00100    );
00101    char *parse;
00102    char *chantech, *chandata;
00103    int res = -1;
00104    int outgoing_res = 0;
00105    int outgoing_status = 0;
00106    static const unsigned int timeout = 30;
00107    static const char default_exten[] = "s";
00108 
00109    ast_autoservice_start(chan);
00110 
00111    if (ast_strlen_zero(data)) {
00112       ast_log(LOG_ERROR, "Originate() requires arguments\n");
00113       goto return_cleanup;
00114    }
00115 
00116    parse = ast_strdupa(data);
00117 
00118    AST_STANDARD_APP_ARGS(args, parse);
00119 
00120    if (args.argc < 3) {
00121       ast_log(LOG_ERROR, "Incorrect number of arguments\n");
00122       goto return_cleanup;
00123    }
00124 
00125    chandata = ast_strdupa(args.tech_data);
00126    chantech = strsep(&chandata, "/");
00127 
00128    if (ast_strlen_zero(chandata) || ast_strlen_zero(chantech)) {
00129       ast_log(LOG_ERROR, "Channel Tech/Data invalid: '%s'\n", args.tech_data);
00130       goto return_cleanup;
00131    }
00132 
00133    if (!strcasecmp(args.type, "exten")) {
00134       int priority = 1; /* Initialized in case priority not specified */
00135       const char *exten = args.arg2;
00136 
00137       if (args.argc == 5) {
00138          /* Context/Exten/Priority all specified */
00139          if (sscanf(args.arg3, "%30d", &priority) != 1) {
00140             ast_log(LOG_ERROR, "Invalid priority: '%s'\n", args.arg3);
00141             goto return_cleanup;
00142          }
00143       } else if (args.argc == 3) {
00144          /* Exten not specified */
00145          exten = default_exten;
00146       }
00147 
00148       ast_debug(1, "Originating call to '%s/%s' and connecting them to extension %s,%s,%d\n",
00149             chantech, chandata, args.arg1, exten, priority);
00150 
00151       outgoing_res = ast_pbx_outgoing_exten(chantech, AST_FORMAT_SLINEAR, chandata,
00152             timeout * 1000, args.arg1, exten, priority, &outgoing_status, 0, NULL,
00153             NULL, NULL, NULL, NULL);
00154    } else if (!strcasecmp(args.type, "app")) {
00155       ast_debug(1, "Originating call to '%s/%s' and connecting them to %s(%s)\n",
00156             chantech, chandata, args.arg1, S_OR(args.arg2, ""));
00157 
00158       outgoing_res = ast_pbx_outgoing_app(chantech, AST_FORMAT_SLINEAR, chandata,
00159             timeout * 1000, args.arg1, args.arg2, &outgoing_status, 0, NULL,
00160             NULL, NULL, NULL, NULL);
00161    } else {
00162       ast_log(LOG_ERROR, "Incorrect type, it should be 'exten' or 'app': %s\n",
00163             args.type);
00164       goto return_cleanup;
00165    }
00166 
00167    res = 0;
00168 
00169 return_cleanup:
00170    if (res) {
00171       pbx_builtin_setvar_helper(chan, "ORIGINATE_STATUS", "FAILED");
00172    } else {
00173       switch (outgoing_status) {
00174       case 0:
00175       case AST_CONTROL_ANSWER:
00176          pbx_builtin_setvar_helper(chan, "ORIGINATE_STATUS", "SUCCESS");
00177          break;
00178       case AST_CONTROL_BUSY:
00179          pbx_builtin_setvar_helper(chan, "ORIGINATE_STATUS", "BUSY");
00180          break;
00181       case AST_CONTROL_CONGESTION:
00182          pbx_builtin_setvar_helper(chan, "ORIGINATE_STATUS", "CONGESTION");
00183          break;
00184       case AST_CONTROL_HANGUP:
00185          pbx_builtin_setvar_helper(chan, "ORIGINATE_STATUS", "HANGUP");
00186          break;
00187       case AST_CONTROL_RINGING:
00188          pbx_builtin_setvar_helper(chan, "ORIGINATE_STATUS", "RINGING");
00189          break;
00190       default:
00191          ast_log(LOG_WARNING, "Unknown originate status result of '%d'\n",
00192                outgoing_status);
00193          pbx_builtin_setvar_helper(chan, "ORIGINATE_STATUS", "UNKNOWN");
00194          break;
00195       }
00196    }
00197 
00198    ast_autoservice_stop(chan);
00199 
00200    return res;
00201 }

static int unload_module ( void   )  [static]

Definition at line 203 of file app_originate.c.

References ast_unregister_application().

00204 {
00205    return ast_unregister_application(app_originate);
00206 }


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 = "8586c2a7d357cb591cc3a6607a8f62d1" , .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_DEFAULT, } [static]

Definition at line 217 of file app_originate.c.

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

Definition at line 45 of file app_originate.c.

struct ast_module_info* ast_module_info = &__mod_info [static]

Definition at line 217 of file app_originate.c.


Generated on Wed Apr 6 11:29:50 2011 for Asterisk - The Open Source Telephony Project by  doxygen 1.4.7